
         <ul id="home" class="topnav">
            		
            <li> <a title="Home" href="/">Home</a></li>
            		
            <li><a title="Lars Vogel's Blog" href="/blog">Blog </a></li>
            		
            <li><a title="Java Tutorials" href="/java.html">Java </a></li>
            		
            <li><a title="Eclipse Tutorials" href="/eclipse.html">Eclipse</a></li>
            		
            <li><a title="Android Tutorials" href="/android.html">Android</a></li>
            		
            <li><a title="Google Tutorials" href="/google.html">Google</a></li>
            	
            		
            <li><a title="Technology Tutorials" href="/technology.html">Technology</a></li>
            		
            <li><a title="Web development Tutorials" href="/web.html">Web</a></li>
            		
            <li><a title="Algorithm Tutorials" href="/algorithms.html">Algorithms</a></li>
            				
            		
            <li><a title="Source Code" href="/code.html">Source
                  		</a>
               		
            </li>
            		
            <li><a title="Trainings Offerings from Lars" href="/training/overview.html">Training</a></li>
            		
            <li> 
               		
               <div id="logo">
                  		<a title="vogella.de" href="/">
                     				<img src="/img/logo/xvogella_current_logo.png.pagespeed.ic.AqzCvNvSQc.png" alt="vogella.de" width="577" height="192"> 
                     		</a>
                  		
               </div>
               		
               		
            </li>
            	
         </ul>
         
         
      </div>
      		
      
      
      
      
      <div id="leftcol">
         
         
         <!-- Google Ads -->
        /javascript" src="//partner.googleadservices.com/gampad/google_service.js"></script>
         <script type="text/javascript">GS_googleAddAdSenseService("ca-pub-3851443674951530");GS_googleEnableAllServices();</script>
         <script type="text/javascript">GA_googleAddSlot("ca-pub-3851443674951530","Wide_Skyscraper");</script>
         <script type="text/javascript">GA_googleFetchAds();</script>
         
         
   
         <script type="text/javascript">GA_googleFillSlot("Wide_Skyscraper");</script>
       dfgsdafsadfsd 
         </div>
      
      
      
      
      <div id="rightcol">
         
         
         <div id="author">
            <a rel="author" href="/about.html"> 
               	<img src="/img/lars/125x115xLarsVogelArticle8.png.pagespeed.ic.-Uv6p5X1eU.png" height="115" width="125" alt="About Lars Vogel">
               </a>
            
         </div>
         
         <p></p>
         by Lars Vogel
         
         
         <p></p>
         
         
         
         <!-- Place this tag in your head or just before your close body tag -->
         <script type="text/javascript" src="//apis.google.com/js/plusone.js"></script>
         
         
         <!-- Place this tag where you want the +1 button to render -->
         <br>
         Please vote +1 if you like this tutorial:
         <br>
         <br>
         
         <div class="g-plusone" data-size="standard" data-count="true"></div>
         
         
         <br>
         
         
         
         
         
         
         <div class="twitter">
            <a href="//www.twitter.com/vogella"> 
               	<img src="/img/common/xtwitter.png.pagespeed.ic._qv3btWJ5_.png" alt="Follow me on twitter" width="150" height="40"> 
               </a>
            
            <p></p>
            <a rel="me" href="https://profiles.google.com/104044918586174763681">
                 <img src="//www.google.com/images/icons/ui/gprofile_button-32.png" alt="Lars Vogel on Google+">
               </a>
            
         </div>
         
         
      </div>
      
      
      
      
      
      <div lang="en" class="article" title="Android 4.0 Development Tutorial">
         <div class="titlepage">
            <div>
               <div class="vogellalogo"><a rel="author" href="/about.html"><img src="/img/logo/202x67xpreface.png.pagespeed.ic.sLxCMVAOlO.png" height="67" width="202" alt="About Lars Vogel"></a></div>
               <div>
                  <h2 class="title"><a name="d0e1"></a> Android 4.0 Development Tutorial
                     		
                  </h2>
               </div>
               <div>
                  <div class="author">
                     <h3 class="author"><span class="firstname">Lars</span> <span class="surname">Vogel</span></h3>
                  </div>
               </div>
               <div>
                  <p class="releaseinfo">Version 8.8	</p>
               </div>
               <div>
                  <p class="copyright">Copyright &copy; 2009 - 2011  Lars Vogel</p>
               </div>
               <div>
                  <p class="pubdate">04.12.2011</p>
               </div>
               <div>
                  <div class="revhistory">
                     <table border="1" width="100%" summary="Revision history">
                        <tr>
                           <th align="left" valign="top" colspan="2"><b>Revision History</b></th>
                        </tr>
                        <tr>
                           <td align="left">Revision 0.1</td>
                           <td align="left">04.07.2009</td>
                        </tr>
                        <tr>
                           <td align="left" colspan="2">Created </td>
                        </tr>
                        <tr>
                           <td align="left">Revision 0.2 - 8.8</td>
                           <td align="left">07.07.2009 - 04.12.2011</td>
                        </tr>
                        <tr>
                           <td align="left" colspan="2">
                              					bug fixing and enhancements
                              				
                           </td>
                        </tr>
                     </table>
                  </div>
               </div>
               <div>
                  <div class="abstract" title="Development with Android Gingerbread and Eclipse"><a name="abstract"></a><p class="title"><b>Development with Android Gingerbread and Eclipse </b></p>
                     <p> This tutorial describes how to create Android
                        				applications with
                        				Eclipse. It is based on Eclipse 3.7 (Indigo), Java 1.6 and Android
                        				4.0 (Ice Cream Sandwich).
                        			
                     </p>
                  </div>
               </div>
            </div>
            <hr>
         </div>
         <div class="toc">
            <p><b>Table of Contents</b></p>
            <dl>
               <dt><span class="section"><a href="#overview">1. What is Android?</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#overview_android">1.1. Android Operation System</a></span></dt>
                     <dt><span class="section"><a href="#overview_terms">1.2. Important Android components </a></span></dt>
                     <dt><span class="section"><a href="#overview_dalvik">1.3. Dalvik Virtual Machine </a></span></dt>
                     <dt><span class="section"><a href="#overview_permissions">1.4. Security and permissions </a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#architecture">2. Android Application Architecture</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#overview_manifest">2.1. AndroidManifest.xml </a></span></dt>
                     <dt><span class="section"><a href="#overview_resources">2.2. R.java, Resources and Assets</a></span></dt>
                     <dt><span class="section"><a href="#overview_reference">2.3. Reference to resources in XML files</a></span></dt>
                     <dt><span class="section"><a href="#overview_layout">2.4. Activities and Layouts </a></span></dt>
                     <dt><span class="section"><a href="#overview_lifecycle">2.5. Activities and Lifecycle </a></span></dt>
                     <dt><span class="section"><a href="#overview_context">2.6. Context </a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#installation">3. Installation</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#installation_eclipse">3.1. Eclipse and automatic Android SDK</a></span></dt>
                     <dt><span class="section"><a href="#installation_androidsdk">3.2. Manually install Android SDK</a></span></dt>
                     <dt><span class="section"><a href="#installation_version">3.3. Install a specific Android version</a></span></dt>
                     <dt><span class="section"><a href="#installation_sourcecode">3.4. Android Source Code</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#emulator">4. Using the Emulator</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#emulator_create">4.1. Create an Android Emulator Device</a></span></dt>
                     <dt><span class="section"><a href="#emulator_using">4.2. Emulator Shortcuts</a></span></dt>
                     <dt><span class="section"><a href="#emulator_performance">4.3. Performance</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#problems">5. Error handling and typical problems</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#problems_clean">5.1. Clean Project</a></span></dt>
                     <dt><span class="section"><a href="#problems_logcat">5.2. LogCat</a></span></dt>
                     <dt><span class="section"><a href="#problems_emulator">5.3. Emulator does not start</a></span></dt>
                     <dt><span class="section"><a href="#problems_override">5.4. Error message for @override </a></span></dt>
                     <dt><span class="section"><a href="#problems_imports">5.5. Missing Imports</a></span></dt>
                     <dt><span class="section"><a href="#problems_tips">5.6. Eclipse Tips</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#first">6. Your first Android project</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#first_project">6.1. Create Project</a></span></dt>
                     <dt><span class="section"><a href="#first_views">6.2. Two faces of things</a></span></dt>
                     <dt><span class="section"><a href="#first_attributes">6.3. Create attributes</a></span></dt>
                     <dt><span class="section"><a href="#first_uielement">6.4. Add UI Elements</a></span></dt>
                     <dt><span class="section"><a href="#first_uiproperties">6.5. Edit UI properties</a></span></dt>
                     <dt><span class="section"><a href="#first_code">6.6. Code your application</a></span></dt>
                     <dt><span class="section"><a href="#first_start">6.7. Start Project</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#start">7. Starting an deployed application</a></span></dt>
               <dt><span class="section"><a href="#menu">8. Menus and Action Bar</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#menu_overview">8.1. Definition of menu entries</a></span></dt>
                     <dt><span class="section"><a href="#menu_tabs">8.2. Action bar tabs</a></span></dt>
                     <dt><span class="section"><a href="#menu_context">8.3. Context menus</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#menu_tutorial">9. Tutorial: Menus and Action Bar</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#menu_project">9.1. Project</a></span></dt>
                     <dt><span class="section"><a href="#menu_add">9.2. Add a menu XML resource</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#preferences">10. Preferences</a></span></dt>
               <dt><span class="section"><a href="#tutorial_preferences">11. Tutorial: Preferences </a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#tutorial_preferences_using">11.1. Using preferences</a></span></dt>
                     <dt><span class="section"><a href="#tutorial_preferences_result">11.2. Run</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#dialog">12. Dialogs via the AlertDialog</a></span></dt>
               <dt><span class="section"><a href="#d0e1258">13. Layouts</a></span></dt>
               <dt><span class="section"><a href="#tablelayout">14. TableLayout</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#tablelayout_overview">14.1. Overview</a></span></dt>
                     <dt><span class="section"><a href="#tablelayout_example">14.2. Example</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#contentprovider">15. ContentProvider</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#contentprovider_overview">15.1. Overview</a></span></dt>
                     <dt><span class="section"><a href="#contentprovider_contacts">15.2. Create contacts on your emulator</a></span></dt>
                     <dt><span class="section"><a href="#contentprovider_example">15.3. Using the Contact Content Provider</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#scrollview">16. ScrollView</a></span></dt>
               <dt><span class="section"><a href="#fragments">17.  Fragments</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#fragments_overview">17.1.  Overview</a></span></dt>
                     <dt><span class="section"><a href="#fragments_overview">17.2.  When to use Fragments</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#fragments_tutorial">18. Fragments Tutorial</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#fragments_tutorial1">18.1. Project and Overview</a></span></dt>
                     <dt><span class="section"><a href="#fragments_tutorial2">18.2. Create layouts</a></span></dt>
                     <dt><span class="section"><a href="#fragments_tutorial3">18.3. Create Fragment classes</a></span></dt>
                     <dt><span class="section"><a href="#fragments_tutorial4">18.4. Activities</a></span></dt>
                     <dt><span class="section"><a href="#fragments_tutorial5">18.5. Run</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#views">19. DDMS perspective and important views</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#views_ddms">19.1. DDMS - Dalvik Debug Monitor Server</a></span></dt>
                     <dt><span class="section"><a href="#views_log">19.2. LogCat View</a></span></dt>
                     <dt><span class="section"><a href="#views_files">19.3. File explorer</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#shell">20. Shell</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#shell_open">20.1. Android Debugging Bridge - Shell</a></span></dt>
                     <dt><span class="section"><a href="#shell_uninstall">20.2. Uninstall an application via adb</a></span></dt>
                     <dt><span class="section"><a href="#emulator_console">20.3. Emulator Console via telnet</a></span></dt>
                  </dl>
               </dd>
               <dt><span class="section"><a href="#deployondevice">21. Deploy your application on a real device</a></span></dt>
               <dt><span class="section"><a href="#thankyou">22. Thank you </a></span></dt>
               <dt><span class="section"><a href="#questions">23. Questions and Discussion</a></span></dt>
               <dt><span class="section"><a href="#resources">24. Links and Literature</a></span></dt>
               <dd>
                  <dl>
                     <dt><span class="section"><a href="#sourcecode">24.1. Source Code</a></span></dt>
                     <dt><span class="section"><a href="#resources_databinding">24.2. Android Resources</a></span></dt>
                     <dt><span class="section"><a href="#resources_general">24.3. vogella Resources</a></span></dt>
                  </dl>
               </dd>
            </dl>
         </div> 
         
         
         
         <img src="//vg03.met.vgwort.de/na/2998b473c5914573a0dccba897dfaafd" width="1" height="1" alt=""><div class="section" title="1.&nbsp;What is Android?">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="overview"></a>1.&nbsp;What is Android?
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="1.1.&nbsp;Android Operation System">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_android"></a>1.1.&nbsp;Android Operation System
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Android is an operating system based on
                  			Linux
                  			with a
                  			Java
                  			programming interface. It provides tools, e.g. a compiler, debugger
                  			and a device emulator as well as its own Java Virtual machine
                  			(Dalvik
                  			Virtual Machine - DVM).
                  		
               </p>
               <p>
                  			Android
                  			is officially
                  			guided by the
                  			Open Handset
                  			Alliance but in
                  			reality Google leads the project.
                  		
               </p>
               <p>
                  			Android supports 2-D and 3-D graphics using the OpenGL
                  			libraries
                  			and
                  			supports data storage in a SQLite
                  			database.
                  		
               </p>
               <p>
                  			Every
                  			Android
                  			applications runs in its own process and under its
                  			own user id which
                  			is generated automatically by the Android system
                  			during deployment.
                  			Therefore the application is
                  			isolated from other
                  			running applications
                  			and a
                  			misbehaving
                  			application cannot
                  			easily harm
                  			other Android
                  			applications.
                  		
               </p>
            </div>
            <div class="section" title="1.2.&nbsp;Important Android components">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_terms"></a>1.2.&nbsp;Important Android components 
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			An Android application consists out of the following parts:
                  			
               </p>
               <div class="itemizedlist">
                  <ul class="itemizedlist" type="disc">
                     <li class="listitem">
                        <p> <code class="code">Activity</code> - represents the presentation layer of an Android
                           						application, e.g. a screen which the user sees. An Android
                           						application can have
                           						several activities and it can be switched
                           						between them during runtime of the application.
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p>
                           						<code class="code">Views</code> - the User interface
                           						of an Activities is built with
                           						widget classes
                           						which inherit from
                           						<code class="code">android.view.View</code>. The layout
                           						of the views is
                           						managed by
                           						<code class="code">android.view.ViewGroups</code>. Views often
                           						have attributes which can be used to change their appearance and
                           						behavior.
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p>
                           						<code class="code">Services</code>
                           						- perform background tasks without providing
                           						an UI.
                           						They can notify
                           						the user via the notification framework in
                           						Android.
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p>
                           						<code class="code">ContentProvider</code> - provides data to applications, via a
                           						content provider your
                           						application can share data with other
                           						applications. Android
                           						contains a SQLite DB which can
                           						serve as data
                           						provider
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p>
                           						<code class="code">Intents</code> -
                           						are asynchronous messages which
                           						allow the application
                           						to
                           						request
                           						functionality from
                           						other services or
                           						activities. An
                           						application can
                           						call directly a
                           						service or activity
                           						(explicit
                           						intent)
                           						or ask the
                           						Android system
                           						for registered
                           						services and
                           						applications for
                           						an intent
                           						(implicit
                           						intents). For
                           						example the
                           						application could
                           						ask via
                           						an
                           						intent for a
                           						contact
                           						application.
                           						Applications register
                           						themselves
                           						to
                           						an
                           						intent via an
                           						<code class="code">IntentFilter</code>.
                           						<code class="code">Intents</code> are a
                           						powerful concept as
                           						they
                           						allow the creation of
                           						loosely
                           						coupled
                           						applications.
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p><code class="code">BroadcastReceiver</code> - receives system messages and implicit
                           						intents, can be used
                           						to react to changed conditions in the system.
                           						An application can register as a <code class="code">BroadcastReceiver</code> for certain
                           						events and can be started if such an event occurs.
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p> <code class="code">Widgets</code> - interactive components primary used on the Android
                           						homescreen to display certain data and to allow the user to have
                           						quick access the the information
                           					
                        </p>
                     </li>
                  </ul>
               </div>
               <p>
                  		
               </p>
               <p>
                  			Other Android components are
                  			Live Folders
                  			and
                  			Android Live
                  			Wallpapers. Live Folders display data on the homescreen without
                  			launching the corresponding application.
                  		
               </p>
            </div>
            <div class="section" title="1.3.&nbsp;Dalvik Virtual Machine">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_dalvik"></a>1.3.&nbsp;Dalvik Virtual Machine 
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Android uses a special virtual machine, e.g. the Dalvik Virtual
                  			Machine. Dalvik uses
                  			special
                  			bytecode. Therefore you cannot run
                  			standard Java bytecode on
                  			Android.
                  			Android provides a tool <code class="code">dx</code> which
                  			allows to convert Java
                  			Class
                  			files
                  			into <code class="code">dex</code> (Dalvik Executable)
                  			files.
                  			Android applications
                  			are
                  			packed into an <code class="code">.apk</code> (Android Package)
                  			file by
                  			the program <code class="code">aapt</code> (Android Asset Packaging Tool) To
                  			simplify
                  			development Google provides the Android Development Tools
                  			(ADT) for Eclipse. The ADT performs automatically the conversion from class to dex
                  			files and creates the apk during deployment.
                  		
               </p>
            </div>
            <div class="section" title="1.4.&nbsp;Security and permissions">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_permissions"></a>1.4.&nbsp;Security and permissions 
                        </h3>
                     </div>
                  </div>
               </div>
               <p>Android defines certain permissions for certain tasks. For
                  			example if the application wants to access the Internet it must
                  			define
                  			in its configuration file that it would like to use the related
                  			permission. During the installation of an Android application the
                  			user receives a screen in which he needs to confirm the required
                  			permissions of the application.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="2.&nbsp;Android Application Architecture">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="architecture"></a>2.&nbsp;Android Application Architecture
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="2.1.&nbsp;AndroidManifest.xml">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_manifest"></a>2.1.&nbsp;AndroidManifest.xml 
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			An Android application is described in the file
                  			<code class="code">AndroidManifest.xml</code>. This file must declare all <code class="code">Activities</code>,
                  			<code class="code">Services</code>, <code class="code">BroadcastReceivers</code>
                  			and <code class="code">ContentProvider</code> of the
                  			application. It must also contain the
                  			required permissions for the
                  			application. For example if
                  			the
                  			application requires network access it
                  			must be specified here.
                  			<code class="code">AndroidManifest.xml</code>
                  			can be
                  			thought as the
                  			deployment descriptor for
                  			an Android application.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hl-tag" style="color: #080">&lt;manifest</span> <span class="hl-attribute" style="color: #7F0055">xmlns:android</span>=<span class="hl-value" style="color: blue">"http://schemas.android.com/apk/res/android"</span>
      <span class="hl-attribute" style="color: #7F0055">package</span>=<span class="hl-value" style="color: blue">"de.vogella.android.temperature"</span>
      <span class="hl-attribute" style="color: #7F0055">android:versionCode</span>=<span class="hl-value" style="color: blue">"1"</span>
      <span class="hl-attribute" style="color: #7F0055">android:versionName</span>=<span class="hl-value" style="color: blue">"1.0"</span><span class="hl-tag" style="color: #080">&gt;</span>
    <span class="hl-tag" style="color: #080">&lt;application</span> <span class="hl-attribute" style="color: #7F0055">android:icon</span>=<span class="hl-value" style="color: blue">"@drawable/icon"</span> <span class="hl-attribute" style="color: #7F0055">android:label</span>=<span class="hl-value" style="color: blue">"@string/app_name"</span><span class="hl-tag" style="color: #080">&gt;</span>
        <span class="hl-tag" style="color: #080">&lt;activity</span> <span class="hl-attribute" style="color: #7F0055">android:name</span>=<span class="hl-value" style="color: blue">".Convert"</span>
                  <span class="hl-attribute" style="color: #7F0055">android:label</span>=<span class="hl-value" style="color: blue">"@string/app_name"</span><span class="hl-tag" style="color: #080">&gt;</span>
            <span class="hl-tag" style="color: #080">&lt;intent-filter&gt;</span>
                <span class="hl-tag" style="color: #080">&lt;action</span> <span class="hl-attribute" style="color: #7F0055">android:name</span>=<span class="hl-value" style="color: blue">"android.intent.action.MAIN"</span><span class="hl-tag" style="color: #080"> /&gt;</span>
                <span class="hl-tag" style="color: #080">&lt;category</span> <span class="hl-attribute" style="color: #7F0055">android:name</span>=<span class="hl-value" style="color: blue">"android.intent.category.LAUNCHER"</span><span class="hl-tag" style="color: #080"> /&gt;</span>
            <span class="hl-tag" style="color: #080">&lt;/intent-filter&gt;</span>
        <span class="hl-tag" style="color: #080">&lt;/activity&gt;</span>

    <span class="hl-tag" style="color: #080">&lt;/application&gt;</span>
    <span class="hl-tag" style="color: #080">&lt;uses-sdk</span> <span class="hl-attribute" style="color: #7F0055">android:minSdkVersion</span>=<span class="hl-value" style="color: blue">"9"</span><span class="hl-tag" style="color: #080"> /&gt;</span>

<span class="hl-tag" style="color: #080">&lt;/manifest&gt;</span> 
			</pre><p>
                  		
               </p>
               <p>
                  			The
                  			<code class="code">package</code>
                  			attribute defines the base package for the
                  			following Java elements. It
                  			also must be unique as the Android
                  			Marketplace only allows application
                  			for a specific package once.
                  			Therefore a good habit is to use your
                  			reverse domain name as a
                  			package
                  			to avoid collisions with other
                  			developers.
                  		
               </p>
               <p>
                  			<code class="code">android:versionName</code>
                  			and
                  			<code class="code">android:versionCode</code>
                  			specify the
                  			version of your application.
                  			<code class="code">versionName</code>
                  			is what the user sees and
                  			can be any string.
                  			<code class="code">versionCode</code>
                  			must be an integer and the Android
                  			Market uses this to determine if
                  			you provided a newer version to
                  			trigger the update on devices which
                  			have your application installed.
                  			You typically start with "1" and
                  			increase this value by one if you
                  			roll-out a new version of your
                  			application.
                  		
               </p>
               <p>
                  
                  			The tag
                  			<code class="code"> &lt;activity&gt; </code>
                  			defines an
                  			<code class="code">Activity</code>, in this
                  			example pointing to the
                  			class
                  			"de.vogella.android.temperature.Convert". An intent filter is
                  			registered for this class which defines that this
                  			<code class="code">Activity</code>
                  			is
                  			started
                  			once
                  			the application starts (action
                  			<code class="code">
                     				android:name="android.intent.action.MAIN"
                     			</code>
                  			). The category definition
                  			<code class="code"> category android:name="android.intent.category.LAUNCHER"</code>
                  			defines
                  			that this application is added to the application directory on
                  			the
                  			Android device. The
                  			<code class="code"> @string/app_name
                     			</code>
                  			value refer to resource files which contain
                  			the actual values. This
                  			makes it easy to provide different
                  			resources,
                  			e.g. strings, colors,
                  			icons, for different devices and makes it easy
                  			to translate
                  			applications.
                  		
               </p>
               <p> The "uses-sdk" part of the "AndroidManifest.xml" defines the
                  			minimal SDK version your application is valid for. This will prevent
                  			your application being installed on devices with older SDK versions.
                  		
               </p>
            </div>
            <div class="section" title="2.2.&nbsp;R.java, Resources and Assets">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_resources"></a>2.2.&nbsp;R.java, Resources and Assets
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			The directory
                  			<code class="code">gen</code>
                  			in an Android project contains generated
                  			values.
                  			<code class="code">R.java</code>
                  			is a
                  			generated class which contains references to
                  			resources of the
                  			<code class="code">res</code>
                  			folder in the project. These resources are
                  			defined in the
                  			<code class="code">res</code>
                  			directory and can
                  			be values, menus, layouts,
                  			icons
                  			or pictures or
                  			animations. For example a resource can be an
                  			image or an
                  			XML file which
                  			defines strings.
                  		
               </p>
               <p>
                  			If you
                  			create a new
                  			resource, the corresponding
                  			reference is
                  			automatically
                  			created in
                  			<code class="code">R.java</code>. The references are static
                  			int values,
                  			the Android
                  			system
                  			provides
                  			methods to access the
                  			corresponding
                  			resource. For
                  			example to
                  			access a
                  			String with the
                  			reference id
                  			<code class="code">R.string.yourString</code>
                  			use the
                  			method
                  			<code class="code">getString(R.string.yourString));</code>. R.java is automatically maintained by the Eclipse development
                  			environment, manual changes are not necessary.
                  		
               </p>
               <p>
                  			While the directory
                  			<code class="code">res</code>
                  			contains structured values which
                  			are
                  			known to the
                  			Android
                  			platform the
                  			directory
                  			<code class="code">assets</code>
                  			can be used
                  			to
                  			store any kind
                  			of
                  			data. In Java you can access this data
                  			via the
                  			<code class="code">AssetsManager</code>
                  			and the
                  			method
                  			<code class="code">getAssets()</code>.
                  		
               </p>
            </div>
            <div class="section" title="2.3.&nbsp;Reference to resources in XML files">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_reference"></a>2.3.&nbsp;Reference to resources in XML files
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			In your XML files, e.g. your layout files you can refer to
                  			other
                  			resources via the
                  			<code class="code"> @ </code>
                  			sign. For example if you want to refer to a
                  			color you defined as
                  			resources you can refer to it via
                  			<code class="code">@color/your_id </code>
                  			or if you have defined a "hello" string as resource you can access it
                  			via
                  			<code class="code"> @string/hello </code>.
                  		
               </p>
            </div>
            <div class="section" title="2.4.&nbsp;Activities and Layouts">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_layout"></a>2.4.&nbsp;Activities and Layouts 
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			The user interface for
                  			<code class="code"> Activities </code>
                  			is defined via layouts.
                  			At
                  			runtime, layouts are instances of
                  			<code class="code">android.view.ViewGroups </code>. The
                  			layout defines the UI elements, their properties and their
                  			arrangement.
                  		
               </p>
               <p>
                  			UI elements are based on the class
                  			<code class="code"> android.view.View </code>.
                  			<code class="code">ViewGroup</code>
                  			is a
                  			subclass of the class
                  			<code class="code"> View </code>
                  			and a layout can contain
                  			UI
                  			components
                  			(
                  			<code class="code"> Views </code>
                  			) or other layouts
                  			(
                  			<code class="code"> ViewGroups </code>
                  			). You should not
                  			nestle
                  			<code class="code">
                     				ViewGroups
                     			</code>
                  			too deeply as this has a negative
                  			impact on
                  			performance.
                  		
               </p>
               <p>
                  			A
                  			layout can be defined via Java code or via XML. You typically
                  			uses Java code to generate the layout if you don't know the content
                  			until runtime; for example if your layout depends on content which
                  			you read
                  			from the Internet.
                  		
               </p>
               <p>
                  
                  			XML based layouts are defined via a
                  			resource
                  			file in
                  			the folder
                  			<code class="code"> /res/layout </code>. This file specifies the
                  			<code class="code"> ViewGroups </code>,
                  			<code class="code"> Views </code>,
                  			their
                  			relationship and
                  			their attributes for a specific layout. If a UI
                  			element needs to be
                  			accessed via Java code you have to give the UI
                  			element an unique id
                  			via the
                  			<code class="code"> android:id </code>
                  			attribute. To assign a new
                  			id to an UI element
                  			use
                  			<code class="code"> @+id/yourvalue </code>. By conversion this will
                  			create and assign a new
                  			id
                  			<code class="code"> yourvalue </code>
                  			to the corresponding UI
                  			element. In your Java code you
                  			can later access
                  			these UI elements via
                  			the method
                  			<code class="code">
                     				findViewById(R.id.yourvalue)
                     			</code>.
                  		
               </p>
               <p>
                  			Defining layouts via
                  			XML
                  			is usually the
                  			preferred way as
                  			this
                  			separates the programming logic
                  			from the layout definition. It also
                  			allows the definition of different layouts
                  			for different
                  			devices. You
                  			can
                  			also mix
                  			both approaches.
                  		
               </p>
            </div>
            <div class="section" title="2.5.&nbsp;Activities and Lifecycle">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_lifecycle"></a>2.5.&nbsp;Activities and Lifecycle 
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			The operating system controls the life cycle of your
                  			application. At
                  			any time the Android system may stop or destroy your
                  			application, e.g.
                  			because of an incoming call. The Android system
                  			defines a life cycle
                  			for activities via pre-defined methods. The most important methods
                  			are:
                  
                  			
               </p>
               <div class="itemizedlist">
                  <ul class="itemizedlist" type="disc">
                     <li class="listitem">
                        <p>
                           						<code class="code"> onSaveInstanceState() </code>
                           						- called if the activity is stopped.
                           						Used to save data so that the
                           						activity can restore its states if
                           						re-started
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p>
                           						<code class="code"> onPause() </code>
                           						- always called if the Activity ends, can be used
                           						to release
                           						resource or save data
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p>
                           						<code class="code"> onResume() </code>
                           						- called if the Activity is re-started, can be
                           						used to initialize
                           						fields
                           					
                        </p>
                     </li>
                  </ul>
               </div>
               <p>
                  		
               </p>
               <p>
                  			The activity will also be
                  			restarted if a so called
                  			"configuration
                  			change" happens. A
                  			configuration change for example
                  			happens if the user
                  			changes the
                  			orientation of the device (vertical or
                  			horizontal). The
                  			activity is
                  			in this case restarted to enable the
                  			Android platform to
                  			load
                  			different resources for these configuration,
                  			e.g. layouts for
                  			vertical or horizontal mode. In the emulator you can
                  			simulate the
                  			change of the orientation via
                  			<span class="shortcut"><strong><span class="keysym">CNTR</span>+<span class="keysym">F11</span></strong></span>.
                  		
               </p>
               <p>
                  			You can avoid a restart of your application for certain
                  			configuration
                  			changes via the configChanges attribute on your
                  			activity definition in
                  			your
                  			<code class="code">AndroidManifest.xml</code>. The following
                  			activity will
                  			not be restarted in case of orientation
                  			changes or
                  			position of the
                  			physical keyboard (hidden / visible).
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-tag" style="color: #080">&lt;activity</span> <span class="hl-attribute" style="color: #7F0055">android:name</span>=<span class="hl-value" style="color: blue">".ProgressTestActivity"</span>
     <span class="hl-attribute" style="color: #7F0055">android:label</span>=<span class="hl-value" style="color: blue">"@string/app_name"</span>
     <span class="hl-attribute" style="color: #7F0055">android:configChanges</span>=<span class="hl-value" style="color: blue">"orientation|keyboardHidden|keyboard"</span><span class="hl-tag" style="color: #080">&gt;</span>
<span class="hl-tag" style="color: #080">&lt;/activity&gt;</span>
			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="2.6.&nbsp;Context">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="overview_context"></a>2.6.&nbsp;Context 
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			The class
                  			<code class="code">android.content.Context</code>
                  			provides the connections to
                  			the
                  			Android system. It is the interface to
                  			global information about
                  			the
                  			application environment. Context also
                  			provides access to Android
                  			<code class="code">Services</code>, e.g. theLocation Service. As Activities and Services extend the
                  			class
                  			<code class="code">Context</code>
                  			you
                  			can directly
                  			access the context via
                  			<code class="code">this</code>.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="3.&nbsp;Installation">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="installation"></a>3.&nbsp;Installation
                     </h2>
                  </div>
               </div>
            </div>
            <p>
               		The following assume that you have already Eclipse installed. For
               		details please
               		see
               		<a class="ulink" href="/articles/Eclipse/article.html" target="_top"> Eclipse Tutorial
                  		</a>.
               	
            </p>
            <div class="section" title="3.1.&nbsp;Eclipse and automatic Android SDK">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="installation_eclipse"></a>3.1.&nbsp;Eclipse and automatic Android SDK
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Use the
                  			Eclipse update manager
                  			to install all available components
                  			for
                  			the
                  			Android Development
                  			Tools
                  			(ADT) from the URL
                  			<a class="ulink" href="https://dl-ssl.google.com/android/eclipse/" target="_top"> https://dl-ssl.google.com/android/eclipse/</a>. If you are not familiar with the Eclipse update manager the usage
                  			is described in
                  			<a class="ulink" href="/articles/Eclipse/article.html#updatemanager" target="_top"> Eclipse update manager</a>.
                  		
               </p>
               <p> After the new Android development components are installed you
                  			will be prompted to install the Android SDK. You can do follow the
                  			following wizard or go to the next section to learn how to do it
                  			manually.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xandroidinstall10.png.pagespeed.ic.8VmRDvn4Av.png" alt="Wizard to install Android SDK - Part 1" width="616" height="460"></div>
               <p>
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xandroidinstall20.png.pagespeed.ic.WeLjdMCDs4.png" alt="Wizard to install Android SDK - Part 2" width="616" height="460"></div>
               <p>
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xandroidinstall30.png.pagespeed.ic.iybvEGvmCR.png" alt="Wizard to install Android SDK - Part 3" width="740" height="370"></div>
               <p>
                  		
               </p>
            </div>
            <div class="section" title="3.2.&nbsp;Manually install Android SDK">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="installation_androidsdk"></a>3.2.&nbsp;Manually install Android SDK
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			The previous step downloads the Android SDK automatically for you.
                  			You can also download the Android SDK manuallz from the Android
                  			homepage under
                  			<a class="ulink" href="//developer.android.com/sdk/index.html" target="_top"> Android SDK download</a>. The download contains a zip file which you can extract to any
                  			place
                  			in
                  			your file system, e.g. I placed it under
                  			"c:\android-sdk-windows".
                  			Avoid
                  			using spaces in the path name otherwise you may experience
                  			problems
                  			later.
                  		
               </p>
               <p>
                  			You also have to define the location of the Android SDK in the
                  			Eclipse Preferences. In Eclipse open the Preferences dialog via
                  			<span class="guimenu">Windows</span> &#8594; <span class="guisubmenu">Preferences</span>. Select
                  			Android and enter the installation path
                  			of the
                  			Android SDK.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xinstall10.png.pagespeed.ic.lOrRWNNw0f.png" alt="Setting up the Android SDK in the Eclipse Preferences" width="704" height="555"></div>
               <p>
                  		
               </p>
            </div>
            <div class="section" title="3.3.&nbsp;Install a specific Android version">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="installation_version"></a>3.3.&nbsp;Install a specific Android version
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			The Android SDK Manager allows you to install specific versions of
                  			Android.
                  			Select
                  			<span class="guimenu">Window</span> &#8594; <span class="guisubmenu">Android SDK Manager</span>
                  			from the Eclipse menu.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xinstall20.png.pagespeed.ic.MJdiKZt_vm.png" alt="Starting ADV Manager" width="218" height="345"></div>
               <p>
                  		
               </p>
               <p>
                  			The dialog allows you to install new package and also allow you
                  			to
                  			delete them.
                  
                  			Select "Available packages" and open the "Third Party
                  			Add-ons".
                  			Select the
                  			Google API 14 (Android 4.0) version of the
                  			SDK and press "Install".
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xinstall30.png.pagespeed.ic.a1mp5xzRuD.png" alt="Install Android API" width="700" height="500"></div>
               <p>
                  		
               </p>
               <p> Press the "Install" button and confirm the license for all
                  			package. After the installation restart Eclipse.
                  		
               </p>
            </div>
            <div class="section" title="3.4.&nbsp;Android Source Code">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="installation_sourcecode"></a>3.4.&nbsp;Android Source Code
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			The following step is optional.
                  		
               </p>
               <p>
                  			During Android development it is very
                  			useful to have the Android
                  			source code available as Android uses a lot
                  			of defaults.
                  		
               </p>
               <p>
                  
                  			<a class="ulink" href="//twitter.com/snpe60" target="_top"> Haris Peco</a>
                  			maintains plugins which provides access to the Android Source code
                  			code. Use
                  			the Eclipse update manager to install the Android Source
                  			plugin from the following update site:
                  			"http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update".
                  		
               </p>
               <p>
                  			More details can be found on the
                  			<a class="ulink" href="//code.google.com/p/adt-addons/" target="_top"> project website</a>.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="4.&nbsp;Using the Emulator">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="emulator"></a>4.&nbsp;Using the Emulator
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="4.1.&nbsp;Create an Android Emulator Device">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="emulator_create"></a>4.1.&nbsp;Create an Android Emulator Device
                        </h3>
                     </div>
                  </div>
               </div>
               <p>The Android tools include an emulator. This emulator behaves
                  			like
                  			a real Android device in most cases and allows you to test your
                  			application without having a real device. You can emulate one or
                  			several devices with different configurations.
                  			Each
                  			configuration is
                  			defined via an "Android
                  			Virtual Device" (AVD).
                  		
               </p>
               <p>
                  			To define an AVD open the "AVD Manager" via
                  			<span class="guimenu">Windows</span> &#8594; <span class="guisubmenu">AVD Manager</span>
                  			and
                  			press "New".
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xinstall50.png.pagespeed.ic.mj7zrqgGSa.png" alt="Create a new AVD" width="500" height="361"></div>
               <p>
                  		
               </p>
               <p>Enter the following.</p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xinstall60.png.pagespeed.ic.DHJMEi2s40.png" alt="Settings for a new AVD" width="400" height="639"></div>
               <p>
                  		
               </p>
               <p> We can also select the box "Enabled" for Snapshots. This will
                  			make
                  			the second start of the virtual device much faster.
                  		
               </p>
               <p> At the end press the button "Create AVD".This will create the
                  			device and display it
                  			under the "Virtual devices". To test if your
                  			setup is correct, select
                  			your device and press
                  			"Start".
                  		
               </p>
               <p> After (a long time) your
                  			device should be started.
                  		
               </p>
            </div>
            <div class="section" title="4.2.&nbsp;Emulator Shortcuts">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="emulator_using"></a>4.2.&nbsp;Emulator Shortcuts
                        </h3>
                     </div>
                  </div>
               </div>
               <p>Obviously you can use the emulator via the keyboard on the right
                  			side of the emulator. But there are also some nice shortcuts which
                  			are
                  			useful.
                  		
               </p>
               <p>
                  			<span class="keycap"><strong>Alt</strong></span>+<span class="keycap"><strong>Enter</strong></span>
                  			maximizes the emulator. Nice for demos.
                  		
               </p>
               <p>
                  			<span class="keycap"><strong>Ctrl</strong></span>+<span class="keycap"><strong>F11</strong></span>
                  			changes the orientation of the emulator.
                  		
               </p>
               <p>
                  			<span class="keycap"><strong>F8</strong></span>
                  			turns network on / off.
                  		
               </p>
            </div>
            <div class="section" title="4.3.&nbsp;Performance">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="emulator_performance"></a>4.3.&nbsp;Performance
                        </h3>
                     </div>
                  </div>
               </div>
               <p>Try to use a smaller resolution for your emulator as for example
                  			HVGA. The emulator gets slower the more pixels its needs to render as
                  			it is using software rendering.
                  		
               </p>
               <p> Also if you have sufficient memory on your computer, add at
                  			least 1 GB of memory to your emulator. This is the value "Device ram
                  			size" during the creation of the AVD.
                  		
               </p>
               <p> Also set the flag "Enabled" for Snapshots. This will save the
                  			state of the emulator and let it start much faster.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="5.&nbsp;Error handling and typical problems">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="problems"></a>5.&nbsp;Error handling and typical problems
                     </h2>
                  </div>
               </div>
            </div>
            <p> Things are not always working as they should. This section gives
               		an overview over typical problems and how to solve them.
               	
            </p>
            <div class="section" title="5.1.&nbsp;Clean Project">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="problems_clean"></a>5.1.&nbsp;Clean Project
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Several users report
                  			that get the following errors:
                  			
               </p>
               <div class="orderedlist">
                  <ol class="orderedlist" type="1">
                     <li class="listitem">
                        <p> Project ... is missing required source folder: 'gen'   </p>
                     </li>
                     <li class="listitem">
                        <p>The project could not be built until build path errors are
                           						resolved.
                           
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p>Unable to open class file R.java.
                           					
                        </p>
                     </li>
                  </ol>
               </div>
               <p>
                  		
               </p>
               <p>To solve any of these errors, go to the project menu and select
                  			Project -&gt; Clean.
                  		
               </p>
            </div>
            <div class="section" title="5.2.&nbsp;LogCat">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="problems_logcat"></a>5.2.&nbsp;LogCat
                        </h3>
                     </div>
                  </div>
               </div>
               <p> The LogCat view shows you the log message of your Android
                  			device and help you analyzing problems. For example Java exceptions
                  			in your program would be shown here. To open this view, select
                  			"Window -&gt; Show View -&gt; Other -&gt; Android -&gt; LogCat" from the menu.
                  		
               </p>
            </div>
            <div class="section" title="5.3.&nbsp;Emulator does not start">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="problems_emulator"></a>5.3.&nbsp;Emulator does not start
                        </h3>
                     </div>
                  </div>
               </div>
               <p> If your emulator does not start, make sure that the androd-sdk
                  			version is in a path without any spaces in the path name.
                  		
               </p>
            </div>
            <div class="section" title="5.4.&nbsp;Error message for @override">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="problems_override"></a>5.4.&nbsp;Error message for @override 
                        </h3>
                     </div>
                  </div>
               </div>
               <p> The @override annotation was introduced in Java 1.6. If you
                  			receive an error message for @override change the Java compiler
                  			level
                  			to Java 1.6 via right-mouse click on the project -&gt; Properties
                  			-&gt;
                  			Java Compiler -&gt; Compiler compliance level and set it to "1.6".
                  		
               </p>
            </div>
            <div class="section" title="5.5.&nbsp;Missing Imports">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="problems_imports"></a>5.5.&nbsp;Missing Imports
                        </h3>
                     </div>
                  </div>
               </div>
               <p> Java requires that the classes which are not part of the
                  			standard Java Language are either fully qualified or declared via
                  			imports. In your editor use the click mouse click, select "Source-&gt;
                  			Organize Imports" if you see error message with "XX cannot be
                  			resolved
                  			to a variable".
                  		
               </p>
            </div>
            <div class="section" title="5.6.&nbsp;Eclipse Tips">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="problems_tips"></a>5.6.&nbsp;Eclipse Tips
                        </h3>
                     </div>
                  </div>
               </div>
               <p> To work more efficient with Eclipse, select Window -&gt;
                  			Preferences -&gt; Java -&gt; Editor -&gt; Save Actions and select that the
                  			source code should be formated and that the imports should be
                  			organized at every save.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="6.&nbsp;Your first Android project">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="first"></a>6.&nbsp;Your first Android project
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="6.1.&nbsp;Create Project">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="first_project"></a>6.1.&nbsp;Create Project
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			This app is also available on the Android Marketplace. Search
                  			for "vogella" for find this example.
                  		
               </p>
               <p>
                  			Select
                  			<span class="guimenu">File</span> &#8594; <span class="guisubmenu">New</span> &#8594; <span class="guisubmenu">Other</span> &#8594; <span class="guisubmenu">Android</span> &#8594; <span class="guisubmenu">Android Project</span>
                  			and
                  			create the
                  			Android project "de.vogella.android.temperature".
                  			Enter
                  			the
                  			following.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirst10.png.pagespeed.ic.-3_PGh7AjJ.png" alt="New Android Project Wizard" width="525" height="474"></div>
               <p>
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirst12.png.pagespeed.ic.m3ur2ZXxVs.png" alt="New Android Project Wizard - Android Target" width="525" height="474"></div>
               <p>
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirst14.png.pagespeed.ic.olP4v_tZbo.png" alt="New Android Project Wizard - Package Definition" width="525" height="474"></div>
               <p>
                  		
               </p>
               <p> Press "Finish". This should create the following directory
                  			structure.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirst20.png.pagespeed.ic.dxGfLV2qE3.png" alt="Android Project Structure" width="432" height="467"></div>
               <p>
                  		
               </p>
               <p> While "res" contains structured values which are known to the
                  			Android platform the directory "assets" can be used to store any kind
                  			of data. In Java you can access this data via the AssetsManager and
                  			the method getAssets().
                  		
               </p>
            </div>
            <div class="section" title="6.2.&nbsp;Two faces of things">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="first_views"></a>6.2.&nbsp;Two faces of things
                        </h3>
                     </div>
                  </div>
               </div>
               <p> The Android SDK allows to define certain artifacts, e.g.
                  			strings and UI's, in two ways, via a rich editor and directly via
                  			XML. The following description tries to use the rich UI but for
                  			validation lists also the XML. You can switch between both things by
                  			clicking on the tab on the lower part of the screen. For example in
                  			the
                  			Package Explorer select "res/layout/main.xml".
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xswitch10.png.pagespeed.ic.t4HOfDtl8D.png" alt="ADT Resource Editor" width="768" height="527"></div>
               <p>
                  		
               </p>
            </div>
            <div class="section" title="6.3.&nbsp;Create attributes">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="first_attributes"></a>6.3.&nbsp;Create attributes
                        </h3>
                     </div>
                  </div>
               </div>
               <p>Android allows you to create attributes for resources, e.g. for
                  			strings and / or colors. These attributes can be used in your UI
                  			definition via XML or in your Java source code.
                  		
               </p>
               <p>
                  			Select the file "res/values/string.xml" and press "Add".
                  			Select
                  			"Color" and enter "myColor" as the name and "#3399CC" as
                  			the
                  			value.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirststring10.gif.pagespeed.ic.2qPDA5vw-N.png" alt="Adding Android Attributes" width="650" height="220"></div>
               <p>
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirststring20.gif.pagespeed.ic.evolO6bBzO.png" alt="Details for a String" width="218" height="146"></div>
               <p>
                  		
               </p>
               <p>
                  			Add also the following "String" attributes. String attributes
                  			allow
                  			to translate the application at a later point.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="table"><a name="d0e751"></a><p class="title"><b>Table&nbsp;1.&nbsp;String Attributes</b></p>
                  <div class="table-contents">
                     <table summary="String Attributes" border="1">
                        <colgroup>
                           <col align="left" class="c1">
                           <col align="left" class="c2">
                        </colgroup>
                        <thead>
                           <tr>
                              <th align="left">Name</th>
                              <th align="left">Value</th>
                           </tr>
                        </thead>
                        <tbody>
                           <tr>
                              <td align="left">celsius</td>
                              <td align="left">to Celsius</td>
                           </tr>
                           <tr>
                              <td align="left">fahrenheit</td>
                              <td align="left">to Fahrenheit</td>
                           </tr>
                           <tr>
                              <td align="left">calc</td>
                              <td align="left">Calculate</td>
                           </tr>
                        </tbody>
                     </table>
                  </div>
               </div>
               <p><br class="table-break">
                  		
               </p>
               <p> Switch to the XML representation and validate
                  			the values.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hl-tag" style="color: #080">&lt;resources&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;string</span> <span class="hl-attribute" style="color: #7F0055">name</span>=<span class="hl-value" style="color: blue">"hello"</span><span class="hl-tag" style="color: #080">&gt;</span>Hello World, Convert!<span class="hl-tag" style="color: #080">&lt;/string&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;string</span> <span class="hl-attribute" style="color: #7F0055">name</span>=<span class="hl-value" style="color: blue">"app_name"</span><span class="hl-tag" style="color: #080">&gt;</span>Temperature Converter<span class="hl-tag" style="color: #080">&lt;/string&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;color</span> <span class="hl-attribute" style="color: #7F0055">name</span>=<span class="hl-value" style="color: blue">"myColor"</span><span class="hl-tag" style="color: #080">&gt;</span>#3399CC<span class="hl-tag" style="color: #080">&lt;/color&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;string</span> <span class="hl-attribute" style="color: #7F0055">name</span>=<span class="hl-value" style="color: blue">"myClickHandler"</span><span class="hl-tag" style="color: #080">&gt;</span>myClickHandler<span class="hl-tag" style="color: #080">&lt;/string&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;string</span> <span class="hl-attribute" style="color: #7F0055">name</span>=<span class="hl-value" style="color: blue">"celsius"</span><span class="hl-tag" style="color: #080">&gt;</span>to Celsius<span class="hl-tag" style="color: #080">&lt;/string&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;string</span> <span class="hl-attribute" style="color: #7F0055">name</span>=<span class="hl-value" style="color: blue">"fahrenheit"</span><span class="hl-tag" style="color: #080">&gt;</span>to Fahrenheit<span class="hl-tag" style="color: #080">&lt;/string&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;string</span> <span class="hl-attribute" style="color: #7F0055">name</span>=<span class="hl-value" style="color: blue">"calc"</span><span class="hl-tag" style="color: #080">&gt;</span>Calculate<span class="hl-tag" style="color: #080">&lt;/string&gt;</span>
<span class="hl-tag" style="color: #080">&lt;/resources&gt;</span>
			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="6.4.&nbsp;Add UI Elements">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="first_uielement"></a>6.4.&nbsp;Add UI Elements
                        </h3>
                     </div>
                  </div>
               </div>
               <p> Select "res/layout/main.xml" and open the Android editor via a
                  			double-click. This editor allows you to create the UI via drag and
                  			drop
                  			or via the XML source code. You can switch between both
                  			representations via the tabs at the bottom of the editor. For
                  			changing the position and grouping elements you can use the outline
                  			view.
                  
                  		
               </p>
               <p>The following shows a screenshot of the Palette view from which
                  			you can drag and drop new UI elements into your layout. Please note
                  			that the
                  			"Palette" view changes frequently so your
                  			view might be a bit
                  			different.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xpalette10.png.pagespeed.ic._SXAv57qNz.png" alt="Palette for the Android Layout Editor" width="166" height="440"></div>
               <p>
                  		
               </p>
               <p>
                  			Right-click on the text object &#8220;Hello World, Hello!&#8221; in the
                  			layout. Select Delete on the popup menu to remove the text object.
                  			Then, from the &#8220;Palette&#8221; view, select Text Fields and locate &#8220;Plain
                  			Text&#8221;. Drag this onto the layout to create a text input field. All
                  			object types in the section "Text Fields&#8221; derive from the
                  			class
                  			"EditText", they just specify via an additional attribute which text
                  			type can be used.
                  		
               </p>
               <p>
                  			Now select the Palette section &#8220;Form Widgets&#8221; and drag a
                  			&#8220;RadioGroup&#8221;
                  			object onto the layout. The number of radio buttons added
                  			to the radio
                  			button group depends on your version of Eclipse. Make
                  			sure there are
                  			two radio buttons by deleting or adding radio buttons
                  			to the group.
                  		
               </p>
               <p>
                  			From the Palette section Form Widgets, drag a Button object
                  			onto
                  			the
                  			layout.
                  		
               </p>
               <p>
                  			The result
                  			should look like the
                  			following.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirst40.png.pagespeed.ic.GZGNDctX7-.png" alt="Current layout of main.xml" width="240" height="393"></div>
               <p>
                  		
               </p>
               <p> Switch to "main.xml" and verify that your XML looks like the
                  			following.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hl-tag" style="color: #080">&lt;LinearLayout</span> <span class="hl-attribute" style="color: #7F0055">xmlns:android</span>=<span class="hl-value" style="color: blue">"http://schemas.android.com/apk/res/android"</span>
	<span class="hl-attribute" style="color: #7F0055">android:orientation</span>=<span class="hl-value" style="color: blue">"vertical"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"fill_parent"</span>
	<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"fill_parent"</span><span class="hl-tag" style="color: #080">&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;EditText</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/editText1"</span>
		<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"match_parent"</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"EditText"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/EditText&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;RadioGroup</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/radioGroup1"</span>
		<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"match_parent"</span><span class="hl-tag" style="color: #080">&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;RadioButton</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"RadioButton"</span>
			<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/radio0"</span>
			<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:checked</span>=<span class="hl-value" style="color: blue">"true"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/RadioButton&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;RadioButton</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"RadioButton"</span>
			<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/radio1"</span>
			<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/RadioButton&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;/RadioGroup&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;Button</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Button"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/button1"</span>
		<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/Button&gt;</span>
<span class="hl-tag" style="color: #080">&lt;/LinearLayout&gt;</span>

			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="6.5.&nbsp;Edit UI properties">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="first_uiproperties"></a>6.5.&nbsp;Edit UI properties
                        </h3>
                     </div>
                  </div>
               </div>
               <p> If you select a UI element you can change its properties via
                  			the properties view. Most of the properties can be changed via
                  			the
                  			right mouse menu. You can also edit properties of fields directy in
                  			XML. Typically you change properties directly in the XML file as this
                  			is much faster. But the right mouse functionality is nice if you are
                  			searching for a certain property.
                  
                  		
               </p>
               <p>
                  			We will delete the intial text for the EditText field in XML.
                  			Switch to
                  			the "main.xml" tab and delete the "android:text="EditText"
                  			property from the EditText part. Switch back to the "Graphical
                  			Layout" tab and check that the text is removed.
                  		
               </p>
               <p> Use the right mouse click on the first radio button to assign
                  			the "celsius" string attribute to its "text" property. Assign the and
                  			"fahrenheit" string attribute to the second radio button.
                  
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirst43.png.pagespeed.ic.0SR2x4GiFE.png" alt="Change the text property of the radio button" width="284" height="392"></div>
               <p>
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirst44.png.pagespeed.ic.H1VqH08FND.png" alt="Selection of the right text from the pre-defined string values" width="315" height="465"></div>
               <p>
                  		
               </p>
               <p>
                  			From now on I assume you are able to use the properties menu on
                  			the UI
                  			elements. You can either edit the XML file or modify the
                  			properties via right mouse click.
                  		
               </p>
               <p>
                  
                  			Set the
                  			property "Checked" to true for the first
                  			RadioButton.
                  			Assign
                  			"calc"
                  			to
                  			the text property of your button and
                  			assign
                  			"myClickHandler"
                  			to the
                  			"onClick" property. Set
                  			the
                  			"Input type"
                  			property
                  			to "numberSigned" and
                  			"numberDecimal" on your EditText.
                  		
               </p>
               <p>
                  			All your other UI controls are contained in a LinearLayout. We
                  			want to
                  			assign a background color to this LinearLayout.
                  			Right-click on
                  			an empty
                  			space in Graphical Layout mode, then
                  			select
                  			<span class="guimenu">Other Properties</span> &#8594; <span class="guisubmenu">All by Name</span> &#8594; <span class="guisubmenu">Background</span>.
                  			Select
                  			&#8220;Color&#8221; and
                  			then &#8220;myColor&#8221; in the list.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirst46.png.pagespeed.ic.7AZsb5H9qb.png" alt="New look of the layout after the changes" width="240" height="286"></div>
               <p>
                  		
               </p>
               <p> Switch to the "main.xml" tab and verify that the XML is
                  			correctly maintained.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hl-tag" style="color: #080">&lt;LinearLayout</span> <span class="hl-attribute" style="color: #7F0055">xmlns:android</span>=<span class="hl-value" style="color: blue">"http://schemas.android.com/apk/res/android"</span>
	<span class="hl-attribute" style="color: #7F0055">android:orientation</span>=<span class="hl-value" style="color: blue">"vertical"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"fill_parent"</span>
	<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"fill_parent"</span> <span class="hl-attribute" style="color: #7F0055">android:background</span>=<span class="hl-value" style="color: blue">"@color/myColor"</span><span class="hl-tag" style="color: #080">&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;EditText</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/editText1"</span>
		<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"match_parent"</span> <span class="hl-attribute" style="color: #7F0055">android:inputType</span>=<span class="hl-value" style="color: blue">"numberDecimal|numberSigned"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/EditText&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;RadioGroup</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/radioGroup1"</span>
		<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"match_parent"</span><span class="hl-tag" style="color: #080">&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;RadioButton</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
			<span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/radio0"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
			<span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"@string/celsius"</span> <span class="hl-attribute" style="color: #7F0055">android:checked</span>=<span class="hl-value" style="color: blue">"true"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/RadioButton&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;RadioButton</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
			<span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/radio1"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
			<span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"@string/fahrenheit"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/RadioButton&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;/RadioGroup&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;Button</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/button1"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
		<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"@string/calc"</span>
		<span class="hl-attribute" style="color: #7F0055">android:onClick</span>=<span class="hl-value" style="color: blue">"myClickHandler"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/Button&gt;</span>
<span class="hl-tag" style="color: #080">&lt;/LinearLayout&gt;</span>

			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="6.6.&nbsp;Code your application">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="first_code"></a>6.6.&nbsp;Code your application
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			During the generation of your new Android project you specified that
                  			an
                  			<code class="code"> Activity</code>
                  			called
                  			<code class="code">CovertActivity</code>
                  
                  			should get created. The project wizard also created the correspondig
                  			Java classs.
                  		
               </p>
               <p>
                  
                  			Change your code in
                  			<code class="code"> ConvertActivity.java</code>
                  			to the following. Note that
                  			the
                  			<code class="code">myClickHandler</code>
                  			will be called based
                  			on the
                  			<code class="code">OnClick</code>
                  			property
                  			of your button.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.temperature;

<span class="hl-keyword">import</span> android.app.Activity;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.view.View;
<span class="hl-keyword">import</span> android.widget.EditText;
<span class="hl-keyword">import</span> android.widget.RadioButton;
<span class="hl-keyword">import</span> android.widget.Toast;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> ConvertActivity <span class="hl-keyword">extends</span> Activity {
	<span class="hl-keyword">private</span> EditText text;

	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		text = (EditText) findViewById(R.id.editText1);

	}

	<em class="hl-comment" style="color: #080">// This method is called at button click because we assigned the name to the</em>
	<em class="hl-comment" style="color: #080">// "On Click property" of the button</em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> myClickHandler(View view) {
		<span class="hl-keyword">switch</span> (view.getId()) {
		<span class="hl-keyword">case</span> R.id.button1:
			RadioButton celsiusButton = (RadioButton) findViewById(R.id.radio0);
			RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radio1);
			<span class="hl-keyword">if</span> (text.getText().length() == <span class="hl-number">0</span>) {
				Toast.makeText(<span class="hl-keyword">this</span>, <span class="hl-string" style="color:blue">"Please enter a valid number"</span>,
						Toast.LENGTH_LONG).show();
				<span class="hl-keyword">return</span>;
			}

			<span class="hl-keyword">float</span> inputValue = Float.parseFloat(text.getText().toString());
			<span class="hl-keyword">if</span> (celsiusButton.isChecked()) {
				text.setText(String
						.valueOf(convertFahrenheitToCelsius(inputValue)));
				celsiusButton.setChecked(false);
				fahrenheitButton.setChecked(true);
			} <span class="hl-keyword">else</span> {
				text.setText(String
						.valueOf(convertCelsiusToFahrenheit(inputValue)));
				fahrenheitButton.setChecked(false);
				celsiusButton.setChecked(true);
			}
			<span class="hl-keyword">break</span>;
		}
	}

	<em class="hl-comment" style="color: #080">// Converts to celsius</em>
	<span class="hl-keyword">private</span> <span class="hl-keyword">float</span> convertFahrenheitToCelsius(<span class="hl-keyword">float</span> fahrenheit) {
		<span class="hl-keyword">return</span> ((fahrenheit - <span class="hl-number">32</span>) * <span class="hl-number">5</span> / <span class="hl-number">9</span>);
	}

	<em class="hl-comment" style="color: #080">// Converts to fahrenheit</em>
	<span class="hl-keyword">private</span> <span class="hl-keyword">float</span> convertCelsiusToFahrenheit(<span class="hl-keyword">float</span> celsius) {
		<span class="hl-keyword">return</span> ((celsius * <span class="hl-number">9</span>) / <span class="hl-number">5</span>) + <span class="hl-number">32</span>;
	}
}
			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="6.7.&nbsp;Start Project">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="first_start"></a>6.7.&nbsp;Start Project
                        </h3>
                     </div>
                  </div>
               </div>
               <p> To start the Android Application, select your project, right
                  			click on it, Run-As-&gt; Android Application Be patient, the emulator
                  			starts up very slow.
                  			You should get the following result.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfirst50.png.pagespeed.ic.SQ3cSUOqYC.png" alt="The running application in the emulator" width="333" height="491"></div>
               <p>
                  		
               </p>
               <p> Type in a number, select your conversion and press the button.
                  			The result should be displayed and the other option should get
                  			selected.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="7.&nbsp;Starting an deployed application">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="start"></a>7.&nbsp;Starting an deployed application
                     </h2>
                  </div>
               </div>
            </div>
            <p>After you ran your application on the virtual device you can
               		start it again on the device. If you press the Home button you can
               		also select your
               		application.
               	
            </p>
            <p>
               		
            </p>
            <div class="mediaobject"><img src="images/xstart10.png.pagespeed.ic.5VCWVuNqNB.png" alt="How to select your application from the Android home menu" width="797" height="562"></div>
            <p>
               	
            </p>
            <p>
               		
            </p>
            <div class="mediaobject"><img src="images/xstart20.png.pagespeed.ic.IK4b5x01Ql.png" alt="Selecting the application from the application choicer" width="333" height="493"></div>
            <p>
               	
            </p>
         </div> 
         <script type="text/javascript">google_ad_client="pub-3851443674951530";google_ad_slot="8639282357";google_ad_width=728;google_ad_height=90;</script>
         <script type="text/javascript" src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script>
         <div class="section" title="8.&nbsp;Menus and Action Bar">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="menu"></a>8.&nbsp;Menus and Action Bar
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="8.1.&nbsp;Definition of menu entries">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="menu_overview"></a>8.1.&nbsp;Definition of menu entries
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Android provides two possible ways to display global actions
                  			which the
                  			user can select. The first one is the usage of the Action
                  			Bar in the
                  			application. The Action Bar is a window feature at the top
                  			of the
                  			activity that may
                  			display the activity title, navigation modes,
                  			and
                  			other interactive
                  			items.
                  
                  		
               </p>
               <p>
                  			The second option is that the app can open a menu which show
                  			additional
                  			actions via a popup menu. Typical you define your menu
                  			entries in a
                  			way that they are added to the action bar if sufficient
                  			space is
                  			available in the action bar and if not that remaining menu
                  			items are
                  			displayed in the popup menu.
                  		
               </p>
               <p>
                  			The option menu and the action bar of your
                  			activity is
                  			filled by
                  			the
                  			method onCreateOptionsMenu() of your
                  			activity.
                  		
               </p>
               <p>
                  			The
                  			<code class="code">ActionBar</code>
                  			also shows an icon of your application. You can also add an
                  			action to
                  			this icon. If you select this icon the
                  			<code class="code">onOptionsItemSelected()</code>
                  			method will be called with the value
                  			<code class="code">android.R.id.home</code>. The recommendation is to return to the main
                  			<code class="code"> Activity</code>
                  			in your program.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<em class="hl-comment" style="color: #080">// If home icon is clicked return to main Activity</em>
<span class="hl-keyword">case</span> android.R.id.home:
	Intent intent = <span class="hl-keyword">new</span> Intent(<span class="hl-keyword">this</span>, OverviewActivity.<span class="hl-keyword">class</span>);
	intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	startActivity(intent);
	<span class="hl-keyword">break</span>;
			</pre><p>
                  		
               </p>
               <p>
                  			In this method you can create the menu programmatically or you
                  			can use a pre-defined XML
                  			resources which
                  			you inflate
                  			via the class
                  			"MenuInflator". Each activity has already an instance of the class
                  			available and this instance can get accessed via the
                  			method
                  			getMenuInflator().
                  		
               </p>
               <p>onCreateContextMenu() is only called once. If you want to
                  			influence the menu later you have to use the method
                  			onPrepareOptionsMenu().
                  		
               </p>
            </div>
            <div class="section" title="8.2.&nbsp;Action bar tabs">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="menu_tabs"></a>8.2.&nbsp;Action bar tabs
                        </h3>
                     </div>
                  </div>
               </div>
               <p>It is also possible to add tabs to an action bar. </p>
            </div>
            <div class="section" title="8.3.&nbsp;Context menus">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="menu_context"></a>8.3.&nbsp;Context menus
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			You can also assign a context menu to an UI
                  			widget
                  			(view). A
                  			context menu is activated if the user "long
                  			presses"
                  			the
                  			view.
                  		
               </p>
               <p>
                  			A context menu for a view is
                  			registered via the method
                  			registerForContextMenu(view). The method onCreateContextMenu() is
                  			called every time a context menu is activated as the context menu is
                  			discarded after its usage. The Android platform may also add options
                  			to your view, e.g. "EditText" provides context options to select
                  			text, etc.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="9.&nbsp;Tutorial: Menus and Action Bar">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="menu_tutorial"></a>9.&nbsp;Tutorial: Menus and Action Bar
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="9.1.&nbsp;Project">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="menu_project"></a>9.1.&nbsp;Project
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			This chapter will demonstrate how to create and evaluate a
                  			option
                  			menu which is displayed in the action bar if sufficient space
                  			is available. This example will be extended in the chapter about
                  			preferences.
                  		
               </p>
               <p>
                  			Create a project "de.vogella.android.socialapp" with the
                  			activity
                  			"OverviewActivity". Change the UI in the file
                  			"/res/layout/main.xml"
                  			to the following: 
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hl-tag" style="color: #080">&lt;LinearLayout</span> <span class="hl-attribute" style="color: #7F0055">xmlns:android</span>=<span class="hl-value" style="color: blue">"http://schemas.android.com/apk/res/android"</span>
    <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"fill_parent"</span>
    <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"fill_parent"</span>
    <span class="hl-attribute" style="color: #7F0055">android:orientation</span>=<span class="hl-value" style="color: blue">"vertical"</span><span class="hl-tag" style="color: #080"> &gt;</span>

    <span class="hl-tag" style="color: #080">&lt;Button</span>
        <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/Button01"</span>
        <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
        <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
        <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Show Preferences"</span><span class="hl-tag" style="color: #080"> &gt;</span>
    <span class="hl-tag" style="color: #080">&lt;/Button&gt;</span>

    <span class="hl-tag" style="color: #080">&lt;Button</span>
        <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/Button02"</span>
        <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
        <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
        <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Change Preferences"</span><span class="hl-tag" style="color: #080"> &gt;</span>
    <span class="hl-tag" style="color: #080">&lt;/Button&gt;</span>

<span class="hl-tag" style="color: #080">&lt;/LinearLayout&gt;</span>
			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="9.2.&nbsp;Add a menu XML resource">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="menu_add"></a>9.2.&nbsp;Add a menu XML resource
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Select your project, right
                  			click
                  			on it and
                  			select
                  			<span class="guimenu">New</span> &#8594; <span class="guisubmenu">Other</span> &#8594; <span class="guisubmenu">Android</span> &#8594; <span class="guisubmenu">Android XML File</span>
                  			to create a new XML resource.
                  		
               </p>
               <p>
                  			Select the option "Menu", enter as File "mainmenu.xml" and press
                  			the
                  			button
                  			"Finish".
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xmenu10.png.pagespeed.ic.Nm74USpd2A.png" alt="Creating a new XML resource for the menu" width="459" height="499"></div>
               <p>
                  		
               </p>
               <p>
                  			This will create a new file "mainmenu.xml" in the folder
                  			"res/menu" of
                  			your project. Android provides an nice editor to edit
                  			this file,
                  			unfortunately this editor is not always automatically
                  			used. To use
                  			this editor right-click on your menu file and select
                  			<span class="guimenu">Open with</span> &#8594; <span class="guisubmenu">Android Menu Editor</span>.
                  		
               </p>
               <p>
                  			Switch if necessary to the "Layout" tab of the editor. Press Add
                  			and select "Item". Maintain the
                  			following value. This
                  			defines the
                  			entries in your menu. We will also define that the menu entry is
                  			displayed in the action bar if there is sufficient space available.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xmenu20.png.pagespeed.ic.cmSUSLyEOz.png" alt="How to maintain the menu entries in an menu xml file" width="681" height="693"></div>
               <p>
                  		
               </p>
               <p> Change your Activity class "OverviewActivity" to the following.
                  			The
                  			OnCreateOptionsMenu method is used to create the menu. The
                  			behavior in
                  			"onOptionsItemSelected" is currently hard-coded to show a
                  			Toast and
                  			will soon call the preference settings. In case you want to
                  			disable
                  			or hide menu
                  			items you can use the method
                  			"onPrepareOptionsMenu" which
                  			is called
                  			every time the menu is called.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.socialapp;

<span class="hl-keyword">import</span> android.app.Activity;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.view.Menu;
<span class="hl-keyword">import</span> android.view.MenuInflater;
<span class="hl-keyword">import</span> android.view.MenuItem;
<span class="hl-keyword">import</span> android.widget.Toast;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> OverviewActivity <span class="hl-keyword">extends</span> Activity {
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">boolean</span> onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.mainmenu, menu);
		<span class="hl-keyword">return</span> true;
	}

	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">boolean</span> onOptionsItemSelected(MenuItem item) {
		Toast.makeText(<span class="hl-keyword">this</span>, <span class="hl-string" style="color:blue">"Just a test"</span>, Toast.LENGTH_SHORT).show();
		<span class="hl-keyword">return</span> true;
	}
}
			</pre><p>
                  		
               </p>
               <p> Run your application. As there is enough space in the action
                  			bar your item will be displayed there. If there would be more items
                  			you could press "Menu" on the emulator to see them. If you select the
                  			menu item you should see
                  			a
                  			small info message.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xpreferences08.png.pagespeed.ic.y-APQjK5Me.png" alt="Screenshot of the running application with the menu open" width="320" height="480"></div>
               <p>
                  		
               </p>
               <p> The two "Preference" buttons are not yet active. We will use
                  			them in the next chapter.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="10.&nbsp;Preferences">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="preferences"></a>10.&nbsp;Preferences
                     </h2>
                  </div>
               </div>
            </div>
            <p>
               		Android supports the usage of Preferences to allow you to save
               		data for your application. Preferences
               		are
               		stored as key values. The
               		definition of Preferences can also be done via an XML resource.
               	
            </p>
            <p>Android provides the class "PreferenceActivity" which extends the
               		class Activity. PreferenceActivity supports the simple handling of
               		preferences. This activity can load a preference definition resources
               		via the method addPreferencesFromResource().
               	
            </p>
            <p>
               		To
               		communicate between different components Android uses Intents.
               		Typically the PreferenceActivity is started from another activity via
               		an Intent.
               	
            </p>
            <p> In your application you can access the preference manager via
               		the following:
               	
            </p>
            <p>
               		
            </p><pre class="programlisting">
			
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(<span class="hl-keyword">this</span>);
		</pre><p>
               	
            </p>
            <p> Values can get access via the key of the preference setting.
               	
            </p>
            <p>
               		
            </p><pre class="programlisting">
			
String username = preferences.getString(<span class="hl-string" style="color:blue">"username"</span>, <span class="hl-string" style="color:blue">"n/a"</span>);
		</pre><p>
               	
            </p>
            <p> To create or change preferences you have to call the edit()
               		methods. Once you have changed the value you have to call commit() to
               		apply your changes. 	
            </p>
            <p>
               		
            </p><pre class="programlisting">
			

Editor edit = preferences.edit();
edit.putString(<span class="hl-string" style="color:blue">"username"</span>, <span class="hl-string" style="color:blue">"new_value_for_user"</span>);
edit.commit();

		</pre><p>
               	
            </p>
         </div>
         <div class="section" title="11.&nbsp;Tutorial: Preferences">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="tutorial_preferences"></a>11.&nbsp;Tutorial: Preferences 
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="11.1.&nbsp;Using preferences">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="tutorial_preferences_using"></a>11.1.&nbsp;Using preferences
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			We will continue using the example project
                  			"de.vogella.android.social".
                  		
               </p>
               <p> Create
                  			an Android XML resource "preferences.xml" of type
                  			"PreferenceScreen".
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xpreferences10.png.pagespeed.ic.7nkBhgctzj.png" alt="How to create a XML file for storing preference value definitions" width="525" height="563"></div>
               <p>
                  		
               </p>
               <p>
                  			Open the file via right-mouse click and
                  			<span class="guimenu">Open-with</span> &#8594; <span class="guisubmenu">Android XML Resource Editor</span>.
                  			Press Add, add a "PreferenceCategory" and add two preferences
                  			"EditTextPreferences" to this category : "User" and
                  			"Password".
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xpreferences20.gif.pagespeed.ic.0YIqa8md6Q.png" alt="Adding a category to the preference XML file" width="772" height="237"></div>
               <p>
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xpreferences22.gif.pagespeed.ic.O8W4d9zoMg.png" alt="Adding the field &#34;user&#34; to the preference XML file" width="691" height="230"></div>
               <p>
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xpreferences30.gif.pagespeed.ic.V4Wda8_-kA.png" alt="Adding the field &#34;password&#34; to the preference XML file" width="714" height="234"></div>
               <p>
                  		
               </p>
               <p>
                  			You can also maintain other properties to EditTextField, e.g.
                  			the
                  			inputMethod. Add for example the following attribute to the XML
                  			definition of your password to make the input quoted with
                  			<code class="code">*</code>.
                  			
               </p>
               <p>
                  				
               </p><pre class="programlisting">
					
android:inputType=<span class="hl-string" style="color:blue">"textPassword"</span>
				</pre><p>
                  			
               </p>
               <p>
                  		
               </p>
               <p> Create the
                  			class "MyPreferencesActivity" with extends
                  			PreferenceActivity. This activity will load the
                  			"preference.xml" and
                  			will allow to maintain the values.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.socialapp;

<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.preference.PreferenceActivity;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> MyPreferencesActivity <span class="hl-keyword">extends</span> PreferenceActivity {
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
	    <span class="hl-keyword">super</span>.onCreate(savedInstanceState);
	    addPreferencesFromResource(R.xml.preferences);
	}
}

			</pre><p>
                  		
               </p>
               <p>To make this class available as an activity for Android you need
                  			to register it in your "AndroidManifest.xml" file. Select
                  			"AndroidManifest.xml" and the tab "Application". Scroll to the botton
                  			of the view and add your new
                  			activity via the "Add" button.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xpreferences40.png.pagespeed.ic._aVP6MzM8l.png" alt="How to define a new activity in the AndroidManifest.xml" width="845" height="188"></div>
               <p>
                  		
               </p>
               <p> To make use of our new preference activity and the preference
                  			values we adjust the
                  			"OverviewActivity".
                  			The first button will show the
                  			current values of
                  			the preferences
                  			via a
                  			Toast and the second button will
                  			revert the
                  			maintained user
                  			name to
                  			demonstrate how you could change the
                  			preferences via code.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.socialapp;

<span class="hl-keyword">import</span> android.app.Activity;
<span class="hl-keyword">import</span> android.content.SharedPreferences;
<span class="hl-keyword">import</span> android.content.SharedPreferences.Editor;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.preference.PreferenceManager;
<span class="hl-keyword">import</span> android.view.Menu;
<span class="hl-keyword">import</span> android.view.MenuInflater;
<span class="hl-keyword">import</span> android.view.MenuItem;
<span class="hl-keyword">import</span> android.view.View;
<span class="hl-keyword">import</span> android.view.View.OnClickListener;
<span class="hl-keyword">import</span> android.widget.Button;
<span class="hl-keyword">import</span> android.widget.Toast;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> OverviewActivity <span class="hl-keyword">extends</span> Activity {
	SharedPreferences preferences;
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Button button = (Button) findViewById(R.id.Button01);
		<em class="hl-comment" style="color: #080">// Initialize preferences</em>
		preferences = PreferenceManager.getDefaultSharedPreferences(<span class="hl-keyword">this</span>);

		button.setOnClickListener(<span class="hl-keyword">new</span> OnClickListener() {
			<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onClick(View v) {
				String username = preferences.getString(<span class="hl-string" style="color:blue">"username"</span>, <span class="hl-string" style="color:blue">"n/a"</span>);
				String password = preferences.getString(<span class="hl-string" style="color:blue">"password"</span>, <span class="hl-string" style="color:blue">"n/a"</span>);
				showPrefs(username, password);
			}
		});

		Button buttonChangePreferences = (Button) findViewById(R.id.Button02);
		buttonChangePreferences.setOnClickListener(<span class="hl-keyword">new</span> OnClickListener() {
			<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onClick(View v) {
				
				updatePreferenceValue();
			}
		});
	}
	
	<span class="hl-keyword">private</span> <span class="hl-keyword">void</span> showPrefs(String username, String password){
		Toast.makeText(
				OverviewActivity.<span class="hl-keyword">this</span>,
				<span class="hl-string" style="color:blue">"Input: "</span> + username + <span class="hl-string" style="color:blue">" and password: "</span>
						+ password, Toast.LENGTH_LONG).show();

	}
	
	<span class="hl-keyword">private</span> <span class="hl-keyword">void</span> updatePreferenceValue(){
		Editor edit = preferences.edit();
		String username = preferences.getString(<span class="hl-string" style="color:blue">"username"</span>, <span class="hl-string" style="color:blue">"n/a"</span>);
		<em class="hl-comment" style="color: #080">// We will just revert the current user name and save again</em>
		StringBuffer buffer = <span class="hl-keyword">new</span> StringBuffer();
		<span class="hl-keyword">for</span> (<span class="hl-keyword">int</span> i = username.length() - <span class="hl-number">1</span>; i &gt;= <span class="hl-number">0</span>; i--) {
			buffer.append(username.charAt(i));
		}
		edit.putString(<span class="hl-string" style="color:blue">"username"</span>, buffer.toString());
		edit.commit();
		<em class="hl-comment" style="color: #080">// A toast is a view containing a quick little message for the</em>
		<em class="hl-comment" style="color: #080">// user. We give a little feedback</em>
		Toast.makeText(OverviewActivity.<span class="hl-keyword">this</span>,
				<span class="hl-string" style="color:blue">"Reverted string sequence of user name."</span>,
				Toast.LENGTH_LONG).show();
	}

			</pre><p>
                  		
               </p>
               <p> To open the new preference activity we will use the method
                  			onOptionsItemSelected(). Even
                  			though
                  			we
                  			currently have only one option
                  			in our menu we use a switch
                  			to be
                  			ready
                  			for several new menu entries. To
                  			see the current values of the
                  			preferences we define a button and use
                  			the class
                  			"PreferenceManager"
                  			to get the sharedPreferences.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<em><span class="hl-annotation" style="color: gray">@Override</span></em>
<span class="hl-keyword">public</span> <span class="hl-keyword">boolean</span> onCreateOptionsMenu(Menu menu) {
	MenuInflater inflater = getMenuInflater();
	inflater.inflate(R.menu.mainmenu, menu);
	<span class="hl-keyword">return</span> true;
}

<em class="hl-comment" style="color: #080">// This method is called once the menu is selected</em>
<em><span class="hl-annotation" style="color: gray">@Override</span></em>
<span class="hl-keyword">public</span> <span class="hl-keyword">boolean</span> onOptionsItemSelected(MenuItem item) {
	<span class="hl-keyword">switch</span> (item.getItemId()) {
	<em class="hl-comment" style="color: #080">// We have only one menu option</em>
	<span class="hl-keyword">case</span> R.id.preferences:
		<em class="hl-comment" style="color: #080">// Launch Preference activity</em>
		Intent i = <span class="hl-keyword">new</span> Intent(OverviewActivity.<span class="hl-keyword">this</span>, MyPreferencesActivity.<span class="hl-keyword">class</span>);
		startActivity(i);
		<em class="hl-comment" style="color: #080">// Some feedback to the user</em>
		Toast.makeText(OverviewActivity.<span class="hl-keyword">this</span>, <span class="hl-string" style="color:blue">"Enter your user credentials."</span>,
			Toast.LENGTH_LONG).show();
		<span class="hl-keyword">break</span>;

	}
	<span class="hl-keyword">return</span> true;
}
			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="11.2.&nbsp;Run">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="tutorial_preferences_result"></a>11.2.&nbsp;Run
                        </h3>
                     </div>
                  </div>
               </div>
               <p>Run your application. Press the "menu" hardware button and then
                  			select your menu item "Preferences". You should be able to enter your
                  			user settings then press the back hardware button to return to your
                  			main activity. The saved
                  			values should be
                  			displayed in a small message
                  			windows (Toast) if you press your first button. If you press the
                  			second button the username should be reversed.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xpreferences50.png.pagespeed.ic.V2zxHTPFn1.png" alt="The running application showing the maintenance dialog for the field &#34;user&#34; in the preference activity" width="334" height="495"></div>
               <p>
                  		
               </p>
            </div>
         </div>
         <div class="section" title="12.&nbsp;Dialogs via the AlertDialog">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="dialog"></a>12.&nbsp;Dialogs via the AlertDialog
                     </h2>
                  </div>
               </div>
            </div>
            <p>
               		We have already used a "Toast" which is a small message window
               		which
               		does not take the focus. In this chapter we will use the class
               		"AlertDialog". AlertDialog is used to open a
               		dialog from our activity.
               		This modal dialog gets the focus until the user closes it.
               	
            </p>
            <p>
               		An instance of this
               		class can be created 	by
               		the builder pattern, e.g. you
               		can chain your
               		method calls.
               
            </p>
            <p>
               		You should always open a dialog from the
               		class onCreateDialog(int)
               		as
               		the
               		Android system manages the dialog in
               		this case for you. This
               		method 
               		is
               		automatically called by Android if
               		you call showDialog(int).
               	
            </p>
            <p> Create a new Android project "de.vogella.android.alertdialog"
               		with the activity "ShowMyDialog". Maintain the following layout for
               		"main.xml".
            </p>
            <p>
               		
            </p><pre class="programlisting">
			
<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hl-tag" style="color: #080">&lt;LinearLayout</span> <span class="hl-attribute" style="color: #7F0055">xmlns:android</span>=<span class="hl-value" style="color: blue">"http://schemas.android.com/apk/res/android"</span>
	<span class="hl-attribute" style="color: #7F0055">android:orientation</span>=<span class="hl-value" style="color: blue">"vertical"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"fill_parent"</span>
	<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"fill_parent"</span><span class="hl-tag" style="color: #080">&gt;</span>

	<span class="hl-tag" style="color: #080">&lt;Button</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/Button01"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
		<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Show Simple Dialog"</span>
		<span class="hl-attribute" style="color: #7F0055">android:onClick</span>=<span class="hl-value" style="color: blue">"openMyDialog"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/Button&gt;</span>
<span class="hl-tag" style="color: #080">&lt;/LinearLayout&gt;</span>

		</pre><p>
               	
            </p>
            <p> Change the code of your activity to the following. </p>
            <p>
               		
            </p><pre class="programlisting">
			
<span class="hl-keyword">package</span> de.vogella.android.alertdialog;

<span class="hl-keyword">import</span> android.app.Activity;
<span class="hl-keyword">import</span> android.app.AlertDialog;
<span class="hl-keyword">import</span> android.app.AlertDialog.Builder;
<span class="hl-keyword">import</span> android.app.Dialog;
<span class="hl-keyword">import</span> android.content.DialogInterface;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.view.View;
<span class="hl-keyword">import</span> android.widget.Toast;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> ShowMyDialog <span class="hl-keyword">extends</span> Activity {
	<div class="hl-tag" style="color: #080">/** Called when the activity is first created. */</div>
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);
		setContentView(R.layout.main);

	}

	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> openMyDialog(View view) {
		showDialog(<span class="hl-number">10</span>);
	}

	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">protected</span> Dialog onCreateDialog(<span class="hl-keyword">int</span> id) {
        <span class="hl-keyword">switch</span> (id) {
        <span class="hl-keyword">case</span> <span class="hl-number">10</span>:
            <em class="hl-comment" style="color: #080">// Create out AlterDialog</em>
            Builder builder = <span class="hl-keyword">new</span> AlertDialog.Builder(<span class="hl-keyword">this</span>);
            builder.setMessage(<span class="hl-string" style="color:blue">"This will end the activity"</span>);
            builder.setCancelable(true);
            builder.setPositiveButton(<span class="hl-string" style="color:blue">"I agree"</span>, <span class="hl-keyword">new</span> DialogInterface.OnClickListener() {
                <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onClick(DialogInterface dialog, <span class="hl-keyword">int</span> which) {
                    ShowMyDialog.<span class="hl-keyword">this</span>.finish();
                }
            });
            builder.setNegativeButton(<span class="hl-string" style="color:blue">"No, no"</span>, <span class="hl-keyword">new</span> DialogInterface.OnClickListener() {
                <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onClick(DialogInterface dialog, <span class="hl-keyword">int</span> which) {
                    Toast.makeText(getApplicationContext(),<span class="hl-string" style="color:blue">"Activity will continue"</span>,Toast.LENGTH_LONG).show();
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();
        }
        <span class="hl-keyword">return</span> <span class="hl-keyword">super</span>.onCreateDialog(id);
    }

}
		</pre><p>
               	
            </p>
            <p> If you run your application and click your button you should
               		see
               		your dialog. 
            </p>
            <p>
               		
            </p>
            <div class="mediaobject"><img src="images/xdialog10.png.pagespeed.ic.PUZGSuA3gy.png" alt="Showing the running application with the dialog open" width="324" height="489"></div>
            <p>
               	
            </p>
            <p>
               		More on dialogs can be found on
               		<a class="ulink" href="//developer.android.com/guide/topics/ui/dialogs.html" target="_top">Android Dialogs standard documentation. </a>
               	
            </p>
         </div>
         <div class="section" title="13.&nbsp;Layouts">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="d0e1258"></a>13.&nbsp;Layouts
                     </h2>
                  </div>
               </div>
            </div>
            <p>Android supports different default layout manager. LinearLayout
               		puts all its child elements into a single column or row depending on
               		the orientation attribute. Other types are FrameLayout, RelativeLayout
               		and TableLayout.
               	
            </p>
            <p> All layouts allow to defined attributes. Childs can also define attributes which may be evaluated by their parent layout.
               For example the 
            </p>
         </div>
         <div class="section" title="14.&nbsp;TableLayout">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="tablelayout"></a>14.&nbsp;TableLayout
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="14.1.&nbsp;Overview">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="tablelayout_overview"></a>14.1.&nbsp;Overview
                        </h3>
                     </div>
                  </div>
               </div>
               <p> In earlier chapter we have used the LinearLayout which allows you
                  			to
                  			stack widgets vertical or horizontal. LinearLayout can be nested to achieve nice effects. This chapter will demonstrate
                  the usage of
                  			"TableLayout".  
               </p>
               <p>This layout allows you to organize a view into
                  			a
                  			table format. You
                  			specify via the view group "TableRow" rows for your table. Afterwards
                  			you put widgets into the individual rows. 
                  			
               </p>
               <p>
                  
                  			On the
                  			"TableLayout" you can define
                  			which column should take
                  			additional
                  			space
                  			via the
                  			"android:stretchColumns" attribute. If several columns
                  			should
                  			take the
                  			available space you can specify them as a
                  			comma-separated
                  			list.
                  			Similar you
                  			can use the attribute
                  			"android:shrinkColumn", which
                  			will
                  			try to
                  			word-wrap the content of the
                  			specified widgets and the
                  			attribute
                  			"android:collapseColums" to define
                  			initially hidden columns.
                  			Via Java
                  			you can display / hide these columns
                  			via the method
                  			setColumnVisible().
                  		
               </p>
               <p>
                  			Columns
                  			will be
                  			automatically created based on the maximum number
                  			of widgets
                  			in one
                  			row. Per default each widgets
                  			creates a new column in the row. You can specific via "android:layout_column" the
                  			column a
                  			widget
                  			should go and via "android:layout_span" how many
                  			columns a widget
                  			should
                  			take. 
                  	
               </p>
               <p>You can also put non TableRows in a table. This way you can for
                  			example add dividers between your columns. 
               </p>
            </div>
            <div class="section" title="14.2.&nbsp;Example">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="tablelayout_example"></a>14.2.&nbsp;Example
                        </h3>
                     </div>
                  </div>
               </div>
               <p>Create the project
                  			"de.vogella.android.layout.table" with the
                  			activity
                  			"DemoTableLayout".
                  			Change "main.xml" to the following. 
                  	
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hl-tag" style="color: #080">&lt;LinearLayout</span> <span class="hl-attribute" style="color: #7F0055">xmlns:android</span>=<span class="hl-value" style="color: blue">"http://schemas.android.com/apk/res/android"</span>
	<span class="hl-attribute" style="color: #7F0055">android:orientation</span>=<span class="hl-value" style="color: blue">"vertical"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"fill_parent"</span>
	<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"fill_parent"</span><span class="hl-tag" style="color: #080">&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;TableLayout</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"match_parent"</span>
		<span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/tableLayout1"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
		<span class="hl-attribute" style="color: #7F0055">android:stretchColumns</span>=<span class="hl-value" style="color: blue">"1"</span><span class="hl-tag" style="color: #080">&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;TableRow</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"match_parent"</span>
			<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/tableRow1"</span><span class="hl-tag" style="color: #080">&gt;</span>
			<span class="hl-tag" style="color: #080">&lt;EditText</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Field1"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/editText1"</span>
				<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/EditText&gt;</span>
			<span class="hl-tag" style="color: #080">&lt;EditText</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Field2"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/editText2"</span>
				<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
				<span class="hl-attribute" style="color: #7F0055">android:layout_column</span>=<span class="hl-value" style="color: blue">"2"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/EditText&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;/TableRow&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;View</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/view1"</span>
			<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"4px"</span> <span class="hl-attribute" style="color: #7F0055">android:background</span>=<span class="hl-value" style="color: blue">"#FF0000"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/View&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;TableRow</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/tableRow2"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
			<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span><span class="hl-tag" style="color: #080">&gt;</span>
			<span class="hl-tag" style="color: #080">&lt;EditText</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Field3"</span>
				<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/editText3"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/EditText&gt;</span>
			<span class="hl-tag" style="color: #080">&lt;EditText</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
				<span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Field4"</span>
				<span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/editText4"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/EditText&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;/TableRow&gt;</span>

	<span class="hl-tag" style="color: #080">&lt;/TableLayout&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;Button</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Hide second column"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/collapse"</span>
		<span class="hl-attribute" style="color: #7F0055">android:onClick</span>=<span class="hl-value" style="color: blue">"toggleHiddenRows"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span>
		<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/Button&gt;</span>
<span class="hl-tag" style="color: #080">&lt;/LinearLayout&gt;</span>

			</pre><p>
                  		
               </p>
               <p> Change the activity "DemoTableLayout" to the following to use
                  			the button to hide the second column in the table. 
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.layout.table;

<span class="hl-keyword">import</span> android.app.Activity;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.view.View;
<span class="hl-keyword">import</span> android.widget.Button;
<span class="hl-keyword">import</span> android.widget.TableLayout;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> DemoTableLayout <span class="hl-keyword">extends</span> Activity {
	<span class="hl-keyword">private</span> TableLayout layout;
	<span class="hl-keyword">private</span> Button button;

	<div class="hl-tag" style="color: #080">/** Called when the activity is first created. */</div>
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		layout = (TableLayout) findViewById(R.id.tableLayout1);
		button = (Button) findViewById(R.id.collapse);

	}

	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> toggleHiddenRows(View view) {
		<em class="hl-comment" style="color: #080">// Second row has index 1</em>
		layout.setColumnCollapsed(<span class="hl-number">1</span>, !layout.isColumnCollapsed(<span class="hl-number">1</span>));
		<span class="hl-keyword">if</span> (layout.isColumnCollapsed(<span class="hl-number">1</span>)) {
			button.setText(<span class="hl-string" style="color:blue">"Show second column"</span>);
		} <span class="hl-keyword">else</span> {
			button.setText(<span class="hl-string" style="color:blue">"Hide second column"</span>);
		}
	}
}
			</pre><p>
                  		
               </p>
            </div>
         </div>
         <!-- Lake Quincy Ads -->
         <div class="lqm_ad" lqm_publisher="lqm.javaeclipseandroid.site" lqm_tags="Java%20Mobile%20Android" lqm_zone="ron" lqm_format="728x90"></div>
         <div class="section" title="15.&nbsp;ContentProvider">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="contentprovider"></a>15.&nbsp;ContentProvider
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="15.1.&nbsp;Overview">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="contentprovider_overview"></a>15.1.&nbsp;Overview
                        </h3>
                     </div>
                  </div>
               </div>
               <p> ContentProvider are used to provide data from an application to
                  			another. ContentProvider do not store the data but provide the
                  			interface for other applications to access the data.
                  		
               </p>
               <p> The following example will use an existing context provider
                  			from "Contacts".
                  		
               </p>
            </div>
            <div class="section" title="15.2.&nbsp;Create contacts on your emulator">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="contentprovider_contacts"></a>15.2.&nbsp;Create contacts on your emulator
                        </h3>
                     </div>
                  </div>
               </div>
               <p> For this example we need a few maintained contacts. Select the
                  			home menu and then the menu entry "People" to
                  			create contacts.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xcontact10.png.pagespeed.ic.NYXOxoK0it.png" alt="Selecting the &#34;Contacts&#34; application from the application choicer" width="335" height="494"></div>
               <p>
                  		
               </p>
               <p> The app will ask you if you want to login. Either login or
                  			select "Not now". Press ""Create a new contact". You can create local
                  			contacts.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xcontact20.png.pagespeed.ic.oadEseWZJ9.png" alt="Create a new contact" width="329" height="491"></div>
               <p>
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xcontact30.png.pagespeed.ic.rcgxciehCj.png" alt="Details for a maintained contact" width="332" height="493"></div>
               <p>
                  		
               </p>
               <p>Finish adding your first contact. Afterwards the app allow you
                  			to add more contacts via the + button.As a result you should have a
                  			few new contacts in your application.
                  		
               </p>
            </div>
            <div class="section" title="15.3.&nbsp;Using the Contact Content Provider">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="contentprovider_example"></a>15.3.&nbsp;Using the Contact Content Provider
                        </h3>
                     </div>
                  </div>
               </div>
               <p> Create a new Android project
                  			"de.vogella.android.contentprovider" with the activity
                  			"ContactsView".
                  		
               </p>
               <p> Rename the id of the existing TextView from the example
                  			wizard
                  			to "contactview". Delete the default text. Also change the
                  			layout_height to
                  			"fill_parent".
                  		
               </p>
               <p> The resulting main.xml should look like the following.</p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hl-tag" style="color: #080">&lt;LinearLayout</span> <span class="hl-attribute" style="color: #7F0055">xmlns:android</span>=<span class="hl-value" style="color: blue">"http://schemas.android.com/apk/res/android"</span>
	<span class="hl-attribute" style="color: #7F0055">android:orientation</span>=<span class="hl-value" style="color: blue">"vertical"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"fill_parent"</span>
	<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"fill_parent"</span><span class="hl-tag" style="color: #080">&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;TextView</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"fill_parent"</span>
		<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"fill_parent"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/contactview"</span><span class="hl-tag" style="color: #080"> /&gt;</span>
<span class="hl-tag" style="color: #080">&lt;/LinearLayout&gt;</span>

			</pre><p>
                  		
               </p>
               <p> Access to the contact content provider require a certain
                  			permission
                  			as not all applications should have access to the contact
                  			information.
                  			Open the AndroidManifest.xml, and select the Permissions
                  			tab. On that
                  			tab click the "Add" button, and select "Uses Permission".
                  			From the drop-down list select the entry
                  			"android.permission.READ_CONTACTS".
                  		
               </p>
               <p> Change the coding of the activity.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.contentprovider;

<span class="hl-keyword">import</span> android.app.Activity;
<span class="hl-keyword">import</span> android.database.Cursor;
<span class="hl-keyword">import</span> android.net.Uri;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.provider.ContactsContract;
<span class="hl-keyword">import</span> android.widget.TextView;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> ContactsView <span class="hl-keyword">extends</span> Activity {
	<div class="hl-tag" style="color: #080">/** Called when the activity is first created. */</div>
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		TextView contactView = (TextView) findViewById(R.id.contactview);

		Cursor cursor = getContacts();

		<span class="hl-keyword">while</span> (cursor.moveToNext()) {

			String displayName = cursor.getString(cursor
					.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
			contactView.append(<span class="hl-string" style="color:blue">"Name: "</span>);
			contactView.append(displayName);
			contactView.append(<span class="hl-string" style="color:blue">"\n"</span>);
		}
	}

	<span class="hl-keyword">private</span> Cursor getContacts() {
		<em class="hl-comment" style="color: #080">// Run query</em>
		Uri uri = ContactsContract.Contacts.CONTENT_URI;
		String[] projection = <span class="hl-keyword">new</span> String[] { ContactsContract.Contacts._ID,
				ContactsContract.Contacts.DISPLAY_NAME };
		String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + <span class="hl-string" style="color:blue">" = '"</span>
				+ (<span class="hl-string" style="color:blue">"1"</span>) + <span class="hl-string" style="color:blue">"'"</span>;
		String[] selectionArgs = null;
		String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
				+ <span class="hl-string" style="color:blue">" COLLATE LOCALIZED ASC"</span>;

		<span class="hl-keyword">return</span> managedQuery(uri, projection, selection, selectionArgs,
				sortOrder);
	}

}
			</pre><p>
                  		
               </p>
               <p>
                  			Typically you would display such data in a ListView.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="16.&nbsp;ScrollView">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="scrollview"></a>16.&nbsp;ScrollView
                     </h2>
                  </div>
               </div>
            </div>
            <p> ScrollViews can be used to contain one view that might be to
               		big to fit on one screen. If the view is to big the ScrollView will
               		display a scroll bar to scroll the context. Of course this view can be
               		a layout which can then contain other elements. 
               	
            </p>
            <p> Create an android project "de.vogella.android.scrollview" with
               		the activity "ScrollView". Create the following layout and class.
               	
            </p>
            <p>
               		
            </p><pre class="programlisting">
			
<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hl-tag" style="color: #080">&lt;ScrollView</span> <span class="hl-attribute" style="color: #7F0055">xmlns:android</span>=<span class="hl-value" style="color: blue">"http://schemas.android.com/apk/res/android"</span>
	<span class="hl-attribute" style="color: #7F0055">android:orientation</span>=<span class="hl-value" style="color: blue">"vertical"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"fill_parent"</span>
	<span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"fill_parent"</span> <span class="hl-attribute" style="color: #7F0055">android:fillViewport</span>=<span class="hl-value" style="color: blue">"true"</span><span class="hl-tag" style="color: #080">&gt;</span>

<span class="hl-tag" style="color: #080">&lt;LinearLayout</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/LinearLayout01"</span> <span class="hl-attribute" style="color: #7F0055">android:orientation</span>=<span class="hl-value" style="color: blue">"vertical"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"fill_parent"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span><span class="hl-tag" style="color: #080">&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;TextView</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/TextView01"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"This is a header"</span> <span class="hl-attribute" style="color: #7F0055">android:textAppearance</span>=<span class="hl-value" style="color: blue">"?android:attr/textAppearanceLarge"</span> <span class="hl-attribute" style="color: #7F0055">android:paddingLeft</span>=<span class="hl-value" style="color: blue">"8dip"</span> <span class="hl-attribute" style="color: #7F0055">android:paddingRight</span>=<span class="hl-value" style="color: blue">"8dip"</span> <span class="hl-attribute" style="color: #7F0055">android:paddingTop</span>=<span class="hl-value" style="color: blue">"8dip"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/TextView&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;TextView</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"@+id/TextView02"</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/TextView02"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"fill_parent"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_weight</span>=<span class="hl-value" style="color: blue">"1.0"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/TextView&gt;</span>
	
	<span class="hl-tag" style="color: #080">&lt;LinearLayout</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/LinearLayout02"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span><span class="hl-tag" style="color: #080">&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;Button</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/Button01"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Submit"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_weight</span>=<span class="hl-value" style="color: blue">"1.0"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/Button&gt;</span>
		<span class="hl-tag" style="color: #080">&lt;Button</span> <span class="hl-attribute" style="color: #7F0055">android:id</span>=<span class="hl-value" style="color: blue">"@+id/Button02"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_width</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_height</span>=<span class="hl-value" style="color: blue">"wrap_content"</span> <span class="hl-attribute" style="color: #7F0055">android:text</span>=<span class="hl-value" style="color: blue">"Cancel"</span> <span class="hl-attribute" style="color: #7F0055">android:layout_weight</span>=<span class="hl-value" style="color: blue">"1.0"</span><span class="hl-tag" style="color: #080">&gt;</span><span class="hl-tag" style="color: #080">&lt;/Button&gt;</span>
	<span class="hl-tag" style="color: #080">&lt;/LinearLayout&gt;</span>
<span class="hl-tag" style="color: #080">&lt;/LinearLayout&gt;</span>
<span class="hl-tag" style="color: #080">&lt;/ScrollView&gt;</span>

		</pre><p>
               	
            </p>
            <p>
               		
            </p><pre class="programlisting">
			
<span class="hl-keyword">package</span> de.vogella.android.scrollview;

<span class="hl-keyword">import</span> android.app.Activity;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.view.View;
<span class="hl-keyword">import</span> android.widget.TextView;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> ScrollView <span class="hl-keyword">extends</span> Activity {
    <div class="hl-tag" style="color: #080">/** Called when the activity is first created. */</div>
    <em><span class="hl-annotation" style="color: gray">@Override</span></em>
    <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
        <span class="hl-keyword">super</span>.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView view =	(TextView) findViewById(R.id.TextView02);
        String s=<span class="hl-string" style="color:blue">""</span>;
        <span class="hl-keyword">for</span> (<span class="hl-keyword">int</span> i=<span class="hl-number">0</span>; i &lt; <span class="hl-number">100</span>; i++) {
        	s += <span class="hl-string" style="color:blue">"vogella.de "</span>;
        }
        view.setText(s);
    }
}
		</pre><p>
               	
            </p>
            <p> The attribute "android:fillViewport="true"" ensures that the the
               		scrollview is set to the full screen even if the elements are smaller
               		then one screen and the "layout_weight" tell the android system that
               		these elements should be extended. 
            </p>
            <p>
               		
            </p>
            <div class="mediaobject"><img src="images/xscrollview10.png.pagespeed.ic.7fLGkQfpy0.png" alt="Showing the running application with the ScrollView in action" width="332" height="490"></div>
            <p>
               	
            </p>
         </div>
         <div class="section" title="17.&nbsp; Fragments">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="fragments"></a>17.&nbsp; Fragments
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="17.1.&nbsp; Overview">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="fragments_overview"></a>17.1.&nbsp; Overview
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			<code class="code">Fragments</code>
                  			allow to organize your application code so that it is
                  			easier to
                  			support
                  			different sized devices.
                  		
               </p>
               <p>
                  			<code class="code">Fragments</code>
                  			are components with its own lifecycle and their own user
                  			interface.
                  			They can be defined via layout files or via coding.
                  			<code class="code">Fragments</code>
                  			run always in the context of an
                  			<code class="code"> Activity</code>. If an
                  			<code class="code"> Activity</code>
                  			is stopped its
                  			<code class="code">Fragments</code>
                  			will also be stopped, if an
                  			<code class="code">Activity</code>
                  			is destroyed its
                  			<code class="code">Fragments</code>
                  			will also get destroyed.
                  		
               </p>
               <p>
                  			If a
                  			<code class="code">Fragments</code>
                  			is defined in an XML layout file, the
                  			<code class="code"> android:name</code>
                  			attribute points to the
                  			<code class="code">Fragments</code>
                  			class.
                  		
               </p>
               <p>
                  			The base class for
                  			<code class="code">Fragments</code>
                  			is
                  			<code class="code">android.app.Fragment</code>. For special purposes you can also use more special classes, like
                  			<code class="code">ListFragment</code>
                  			or
                  			<code class="code">DialogFragment</code>.
                  		
               </p>
               <p>
                  			The onCreateView() method is called by Android once the
                  			<code class="code">Fragment</code>
                  			should create its user interface. Here you can inflate an layout. The
                  			<code class="code">
                     				onStart() method is called once the
                     				<code class="code"> Fragment</code>
                     				gets visible.
                     			</code>
                  		
               </p>
               <p>
                  			Fragments
                  			can be dynamically added and removed from an
                  			<code class="code"> Activity</code>
                  			via
                  			<code class="code"> Fragment</code>
                  			transactions. This will add the actioin to the history stack of the
                  			<code class="code"> Activity</code>, i.e. this will allow to revert them via the back button.
                  		
               </p>
            </div>
            <div class="section" title="17.2.&nbsp; When to use Fragments">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="fragments_overview"></a>17.2.&nbsp; When to use Fragments
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			<code class="code">Fragments</code>
                  			allow to be re-used for different layouts, e.g. you
                  			can
                  			build
                  			single-pane layouts for handsets (phones) and multi-pane
                  			layouts
                  			for
                  			tablets. This is not limited to tables, for example you can use
                  			<code class="code">Fragments</code>
                  			also to support different layout for landscape and portrait
                  			orientation. But as tablets offer signification more space you
                  			typically include more views into the layout and
                  			<code class="code">Fragments</code>
                  			makes that
                  			easier.
                  		
               </p>
               <p>
                  			The typical example is a list of items in an activity. On a
                  			tablet you
                  			see the
                  			details immediately on the same screen on the right
                  			hand side
                  			if
                  			you
                  			click on item. On a handset you jump to a new detail
                  			screen. The
                  			following discussion will assume that you have two
                  			<code class="code">Fragments</code>
                  			(main and
                  			detail) but you can also have more. We will also
                  			have one
                  			main
                  			activity and one detailed activity. On a tablet the main
                  			activity
                  			contains both
                  			<code class="code">Fragments</code>
                  			in its layout, on a handheld it only
                  			contains the main fragment.
                  		
               </p>
               <p>To check for an fragment you can use the FragmentManager.</p>
               <p>
                  			
               </p><pre class="programlisting">
				
DetailFragment detailFragement = (DetailFragment) getFragmentManager().findFragmentById(R.id.detail_frag);
<span class="hl-keyword">if</span> (detailFragement==null) {
	<em class="hl-comment" style="color: #080">// start new Activity</em>
	}
<span class="hl-keyword">else</span> {
	detailFragement.update(...);
}

			</pre><p>
                  		
               </p>
               <p>
                  			To create different layouts with
                  			<code class="code">Fragments</code>
                  			you can:
                  
                  			
               </p>
               <div class="itemizedlist">
                  <ul class="itemizedlist" type="disc">
                     <li class="listitem">
                        <p>
                           						Use one activity, which displays two
                           						<code class="code">Fragments</code>
                           						for tablets
                           						and only one on handsets devices. In this case you
                           						would
                           						switch the
                           						<code class="code">Fragments</code>
                           						in the activity whenever necessary. This requires that
                           						the fragment
                           						is not declared in the layout file as such
                           						<code class="code">Fragments</code>
                           						cannot be removed during runtime. It also requires an update of
                           						the
                           						action bar if the action bar status depends on the fragment.
                           					
                        </p>
                     </li>
                     <li class="listitem">
                        <p>
                           						Use separate activities to host each fragment on a handset.
                           						For
                           						example, when the tablet UI uses two
                           						<code class="code">Fragments</code>
                           						in an activity,
                           						use the same activity for handsets, but supply an
                           						alternative
                           						layout that includes just one fragment. When you need
                           						to
                           						switch
                           						<code class="code">Fragments</code>, start another
                           						activity that hosts the other fragment.
                           					
                        </p>
                     </li>
                  </ul>
               </div>
               <p>
                  		
               </p>
               <p>
                  			The second approach is the most flexible and in general
                  			preferable way
                  			of using
                  			<code class="code">Fragments</code>. In this case the main activity
                  			checks if the detail fragment is
                  			available in the layout. If the
                  			detailed fragment is there, the main
                  			activity tells the fragment that
                  			is should update itself. If the
                  			detail
                  			fragment is not available the
                  			main activity starts the detailed
                  			activity.
                  		
               </p>
               <p>
                  			Its good practice that
                  			<code class="code">Fragments</code>
                  			do not manipulate each other.
                  			For this purpose
                  			<code class="code">Fragments</code>
                  			typically implements an interface to get
                  			new data from its host
                  			activity.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="18.&nbsp;Fragments Tutorial">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="fragments_tutorial"></a>18.&nbsp;Fragments Tutorial
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="18.1.&nbsp;Project and Overview">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="fragments_tutorial1"></a>18.1.&nbsp;Project and Overview
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Create a new project
                  			<code class="code">de.vogella.android.fragments</code>
                  			with the
                  			Activity
                  			<code class="code">MainActivity</code>.
                  		
               </p>
               <p>
                  			We will create two
                  			<code class="code"> Activities</code>. Our
                  			<code class="code">MainActivity</code>
                  			will have two layouts, one for portrait mode and one for all other
                  			(landscape). The portrait layout one will only show one Fragment,
                  			while the landscape layout will show two Fragments.
                  		
               </p>
               <p>
                  			The second
                  			<code class="code"> Activity</code>
                  			called
                  			<code class="code">DetailActivity</code>
                  			will only be used
                  			in portrait mode and will show items selected in the
                  			<code class="code">MainActivity</code>
                  			on a second screen.
                  		
               </p>
            </div>
            <div class="section" title="18.2.&nbsp;Create layouts">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="fragments_tutorial2"></a>18.2.&nbsp;Create layouts
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			We start with the layout "details.xml". This layout will be used by
                  			the
                  			<code class="code"> DetailFragment</code>.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
&lt;?xml version=<span class="hl-string" style="color:blue">"1.0"</span> encoding=<span class="hl-string" style="color:blue">"utf-8"</span>?&gt;
&lt;LinearLayout xmlns:android=<span class="hl-string" style="color:blue">"http://schemas.android.com/apk/res/android"</span>
    android:layout_width=<span class="hl-string" style="color:blue">"match_parent"</span>
    android:layout_height=<span class="hl-string" style="color:blue">"match_parent"</span>
    android:orientation=<span class="hl-string" style="color:blue">"vertical"</span> &gt;

    &lt;TextView
        android:id=<span class="hl-string" style="color:blue">"@+id/detailsText"</span>
        android:layout_width=<span class="hl-string" style="color:blue">"wrap_content"</span>
        android:layout_height=<span class="hl-string" style="color:blue">"match_parent"</span>
        android:layout_gravity=<span class="hl-string" style="color:blue">"center_horizontal|center_vertical"</span>
        android:layout_marginTop=<span class="hl-string" style="color:blue">"20dip"</span>
        android:text=<span class="hl-string" style="color:blue">"Large Text"</span>
        android:textAppearance=<span class="hl-string" style="color:blue">"?android:attr/textAppearanceLarge"</span>
        android:textSize=<span class="hl-string" style="color:blue">"30dip"</span> /&gt;

&lt;/LinearLayout&gt;
			</pre><p>
                  		
               </p>
               <p>
                  			Create the layout "main.mxl". The layout will be used by
                  			<code class="code">MainActivity</code>
                  			in landscape mode and will show two fragments.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
&lt;?xml version=<span class="hl-string" style="color:blue">"1.0"</span> encoding=<span class="hl-string" style="color:blue">"utf-8"</span>?&gt;
&lt;LinearLayout xmlns:android=<span class="hl-string" style="color:blue">"http://schemas.android.com/apk/res/android"</span>
    android:layout_width=<span class="hl-string" style="color:blue">"fill_parent"</span>
    android:layout_height=<span class="hl-string" style="color:blue">"fill_parent"</span>
    android:orientation=<span class="hl-string" style="color:blue">"horizontal"</span> &gt;

    &lt;fragment
        android:id=<span class="hl-string" style="color:blue">"@+id/listFragment"</span>
        android:layout_width=<span class="hl-string" style="color:blue">"150dip"</span>
        android:layout_height=<span class="hl-string" style="color:blue">"match_parent"</span>
        android:layout_marginTop=<span class="hl-string" style="color:blue">"?android:attr/actionBarSize"</span>
        <span class="hl-keyword">class</span>=<span class="hl-string" style="color:blue">"de.vogella.android.fragments.ListFragment"</span> &gt;&lt;/fragment&gt;

    &lt;fragment
        android:id=<span class="hl-string" style="color:blue">"@+id/detailFragment"</span>
        android:layout_width=<span class="hl-string" style="color:blue">"match_parent"</span>
        android:layout_height=<span class="hl-string" style="color:blue">"match_parent"</span>
        <span class="hl-keyword">class</span>=<span class="hl-string" style="color:blue">"de.vogella.android.fragments.DetailFragment"</span> &gt;
        &lt;!-- Preview: layout=<em><span class="hl-annotation" style="color: gray">@layout/details</span></em> --&gt;
    &lt;/fragment&gt;

&lt;/LinearLayout&gt;
			</pre><p>
                  		
               </p>
               <p>
                  			Create the layout "details_activity_layout.xml". This layout will be
                  			used in the
                  			<code class="code">DetailActivity</code>
                  			which is only used in portrait mode.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
&lt;?xml version=<span class="hl-string" style="color:blue">"1.0"</span> encoding=<span class="hl-string" style="color:blue">"utf-8"</span>?&gt;
&lt;LinearLayout xmlns:android=<span class="hl-string" style="color:blue">"http://schemas.android.com/apk/res/android"</span>
    android:layout_width=<span class="hl-string" style="color:blue">"match_parent"</span>
    android:layout_height=<span class="hl-string" style="color:blue">"match_parent"</span>
    android:orientation=<span class="hl-string" style="color:blue">"vertical"</span> &gt;

    &lt;fragment
        android:id=<span class="hl-string" style="color:blue">"@+id/detailFragment"</span>
        android:layout_width=<span class="hl-string" style="color:blue">"match_parent"</span>
        android:layout_height=<span class="hl-string" style="color:blue">"match_parent"</span>
        <span class="hl-keyword">class</span>=<span class="hl-string" style="color:blue">"de.vogella.android.fragments.DetailFragment"</span> /&gt;

&lt;/LinearLayout&gt;
			</pre><p>
                  		
               </p>
               <p>
                  			in the folder "layout-port" create the following layout
                  			"main.mxl".
                  			This layout will be used by
                  			<code class="code">MainActivity</code>
                  			in landscape mode.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
&lt;?xml version=<span class="hl-string" style="color:blue">"1.0"</span> encoding=<span class="hl-string" style="color:blue">"utf-8"</span>?&gt;
&lt;LinearLayout xmlns:android=<span class="hl-string" style="color:blue">"http://schemas.android.com/apk/res/android"</span>
    android:layout_width=<span class="hl-string" style="color:blue">"fill_parent"</span>
    android:layout_height=<span class="hl-string" style="color:blue">"fill_parent"</span>
    android:orientation=<span class="hl-string" style="color:blue">"horizontal"</span> &gt;

    &lt;fragment
        android:id=<span class="hl-string" style="color:blue">"@+id/listFragment"</span>
        android:layout_width=<span class="hl-string" style="color:blue">"match_parent"</span>
        android:layout_height=<span class="hl-string" style="color:blue">"match_parent"</span>
        android:layout_marginTop=<span class="hl-string" style="color:blue">"?android:attr/actionBarSize"</span>
        <span class="hl-keyword">class</span>=<span class="hl-string" style="color:blue">"de.vogella.android.fragments.ListFragment"</span> /&gt;
&lt;/LinearLayout&gt;
			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="18.3.&nbsp;Create Fragment classes">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="fragments_tutorial3"></a>18.3.&nbsp;Create Fragment classes
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Create now the
                  			<code class="code"> Fragment</code>
                  			classes. Create the
                  			<code class="code">ListFragment</code>
                  			class.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.fragments;

<span class="hl-keyword">import</span> android.content.Intent;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.view.View;
<span class="hl-keyword">import</span> android.widget.ArrayAdapter;
<span class="hl-keyword">import</span> android.widget.ListView;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> ListFragment <span class="hl-keyword">extends</span> android.app.ListFragment {
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);

	}

	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onActivityCreated(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onActivityCreated(savedInstanceState);
		String[] values = <span class="hl-keyword">new</span> String[] { <span class="hl-string" style="color:blue">"Android"</span>, <span class="hl-string" style="color:blue">"iPhone"</span>, <span class="hl-string" style="color:blue">"WindowsMobile"</span>,
				<span class="hl-string" style="color:blue">"Blackberry"</span>, <span class="hl-string" style="color:blue">"WebOS"</span>, <span class="hl-string" style="color:blue">"Ubuntu"</span>, <span class="hl-string" style="color:blue">"Windows7"</span>, <span class="hl-string" style="color:blue">"Max OS X"</span>,
				<span class="hl-string" style="color:blue">"Linux"</span>, <span class="hl-string" style="color:blue">"OS/2"</span> };
		ArrayAdapter&lt;String&gt; adapter = <span class="hl-keyword">new</span> ArrayAdapter&lt;String&gt;(getActivity(),
				android.R.layout.simple_list_item_<span class="hl-number">1</span>, values);
		setListAdapter(adapter);
	}

	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onListItemClick(ListView l, View v, <span class="hl-keyword">int</span> position, <span class="hl-keyword">long</span> id) {
		String item = (String) getListAdapter().getItem(position);
		DetailFragment fragment = (DetailFragment) getFragmentManager()
				.findFragmentById(R.id.detailFragment);
		<span class="hl-keyword">if</span> (fragment != null) {
			fragment.setText(item);
		} <span class="hl-keyword">else</span> {
			Intent intent = <span class="hl-keyword">new</span> Intent(getActivity().getApplicationContext(),
					DetailActivity.<span class="hl-keyword">class</span>);
			intent.putExtra(<span class="hl-string" style="color:blue">"value"</span>, item);
			startActivity(intent);
		}

	}
}

			</pre><p>
                  		
               </p>
               <p>
                  			And create the
                  			<code class="code">DetailFragment</code>.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.fragments;

<span class="hl-keyword">import</span> android.app.Fragment;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.util.Log;
<span class="hl-keyword">import</span> android.view.LayoutInflater;
<span class="hl-keyword">import</span> android.view.View;
<span class="hl-keyword">import</span> android.view.ViewGroup;
<span class="hl-keyword">import</span> android.widget.TextView;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> DetailFragment <span class="hl-keyword">extends</span> Fragment {
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);
		Log.e(<span class="hl-string" style="color:blue">"Test"</span>, <span class="hl-string" style="color:blue">"hello"</span>);
	}

	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onActivityCreated(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onActivityCreated(savedInstanceState);

	}

	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.details, container, false);
		<span class="hl-keyword">return</span> view;
	}

	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> setText(String item) {
		TextView view = (TextView) getView().findViewById(R.id.detailsText);
		view.setText(item);
	}
}

			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="18.4.&nbsp;Activities">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="fragments_tutorial4"></a>18.4.&nbsp;Activities
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Create a new
                  			<code class="code">Activity</code>
                  			called
                  			<code class="code">DetailActivity</code>
                  			with the following class.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.fragments;

<span class="hl-keyword">import</span> android.app.Activity;
<span class="hl-keyword">import</span> android.os.Bundle;
<span class="hl-keyword">import</span> android.widget.TextView;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> DetailActivity <span class="hl-keyword">extends</span> Activity {
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">protected</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);
		setContentView(R.layout.details_activity_layout);
		Bundle extras = getIntent().getExtras();
		<span class="hl-keyword">if</span> (extras != null) {
			String s = extras.getString(<span class="hl-string" style="color:blue">"value"</span>);
			TextView view = (TextView) findViewById(R.id.detailsText);
			view.setText(s);
		}

	}
}

			</pre><p>
                  		
               </p>
               <p>
                  			<code class="code">MainActivity</code>
                  			will remain unmodified.
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
<span class="hl-keyword">package</span> de.vogella.android.fragments;

<span class="hl-keyword">import</span> android.app.Activity;
<span class="hl-keyword">import</span> android.os.Bundle;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> MainActivity <span class="hl-keyword">extends</span> Activity {
	<div class="hl-tag" style="color: #080">/** Called when the activity is first created. */</div>
	<em><span class="hl-annotation" style="color: gray">@Override</span></em>
	<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> onCreate(Bundle savedInstanceState) {
		<span class="hl-keyword">super</span>.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}
}
			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="18.5.&nbsp;Run">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="fragments_tutorial5"></a>18.5.&nbsp;Run
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Run your example. If you run the application in portrait mode you
                  			should see only one
                  			<code class="code">Fragment</code>. Use Ctrl+F11 to switch the orientation. In horizontal mode you
                  			should
                  			see two
                  			<code class="code">Fragment</code>. If you select an item in portrait mode a new
                  			<code class="code"> Activity</code>
                  			should get started with the selected item. In horizontal mode your
                  			second
                  			<code class="code"> Fragment</code>
                  			should display the select item.
                  		
               </p>
            </div>
         </div>
         <div class="section" title="19.&nbsp;DDMS perspective and important views">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="views"></a>19.&nbsp;DDMS perspective and important views
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="19.1.&nbsp;DDMS - Dalvik Debug Monitor Server">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="views_ddms"></a>19.1.&nbsp;DDMS - Dalvik Debug Monitor Server
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			Eclipse provides a
                  			perspective
                  			for interacting with your Android
                  			(virtual) device and your Android
                  			application program. Select
                  			<span class="guimenu">Window</span> &#8594; <span class="guisubmenu">Open Perspective</span> &#8594; <span class="guisubmenu">Other</span> &#8594; <span class="guisubmenu">DDMS</span>
                  
                  			to open this perspective. It includes several views which can also be
                  			used independently and allows to place calls
                  			and send SMS to the
                  			device. It also allow to set the current geo
                  			position and to
                  			 perform a performance trace
                  			of your application.
                  		
               </p>
            </div>
            <div class="section" title="19.2.&nbsp;LogCat View">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="views_log"></a>19.2.&nbsp;LogCat View
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			You can see the log (including System.out.print() statements)
                  			via the
                  			LogCat view.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xlogcat10.png.pagespeed.ic.8z0Dgy2KW9.png" alt="Showing the LogCat view" width="888" height="401"></div>
               <p>
                  		
               </p>
            </div>
            <div class="section" title="19.3.&nbsp;File explorer">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="views_files"></a>19.3.&nbsp;File explorer
                        </h3>
                     </div>
                  </div>
               </div>
               <p>The file explorer allows to see the files on the android
                  			simulator.
                  		
               </p>
               <p>
                  			
               </p>
               <div class="mediaobject"><img src="images/xfileexplorer10.gif.pagespeed.ic.VqrJaNSftj.png" alt="Showing the File Explorer View" width="625" height="429"></div>
               <p>
                  		
               </p>
            </div>
         </div>
         <div class="section" title="20.&nbsp;Shell">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="shell"></a>20.&nbsp;Shell
                     </h2>
                  </div>
               </div>
            </div>
            <div class="section" title="20.1.&nbsp;Android Debugging Bridge - Shell">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="shell_open"></a>20.1.&nbsp;Android Debugging Bridge - Shell
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			You can access your Android emulator also via the console. Open
                  			a
                  			shell, switch to your "android-sdk" installation directory into the
                  			folder "tools". Start the shell via the following command "adb
                  			shell".
                  		
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
adb shell

			</pre><p>
                  		
               </p>
               <p> You can also copy file from and to your device via the
                  			following commands.
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
// Assume the gesture file exists on your Android device
adb pull /sdcard/gestures ~/test
// Now copy it back
adb push ~/test/gesture /sdcard/gestures2 
			</pre><p>
                  		
               </p>
               <p>
                  			This
                  			will connect you to your device and give you
                  			Linux command line
                  				access
                  			to the underlying file system, e.g. ls, rm, mkdir, etc. The
                  			application data is stored in the directory
                  			"/data/data/package_of_your_app".
                  		
               </p>
               <p>If you have several devices running you can issue commands to
                  			one individual device. 
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
# Lists all devices
adb devices
#Result
List of devices attached
emulator-5554 attached
emulator-5555 attached
# Issue a command to a specific device
adb -s emulator-5554 shell

			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="20.2.&nbsp;Uninstall an application via adb">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="shell_uninstall"></a>20.2.&nbsp;Uninstall an application via adb
                        </h3>
                     </div>
                  </div>
               </div>
               <p> You can uninstall an android application via the shell. Switch
                  			the the data/app directory (cd /data/app) and simply delete your
                  			android application. 
               </p>
               <p> You can also uninstall an app via adb with the package name.</p>
               <p>
                  			
               </p><pre class="programlisting">
				
adb uninstall &lt;packagename&gt;
			</pre><p>
                  		
               </p>
            </div>
            <div class="section" title="20.3.&nbsp;Emulator Console via telnet">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="emulator_console"></a>20.3.&nbsp;Emulator Console via telnet
                        </h3>
                     </div>
                  </div>
               </div>
               <p> Alternatively to adb you can also use telnet to connect to the
                  			device. This allows you to simulate certain things, e.g. incoming
                  			call, change the network "stability", set your current geocodes, etc.
                  			Use "telnet localhost 5554" to conntect to your simulated
                  			device. To
                  			exit the console session, use the command "quit" or
                  			"exit".
               </p>
               <p>For example to change the power settings of your phone, to
                  			receive an sms and to get an incoming call make the following. 
               </p>
               <p>
                  			
               </p><pre class="programlisting">
				
# connects to device
telnet localhost 5554
# set the power level
power status full
power status charging
# make a call to the device
gsm call 012041293123
# send a sms to the device
sms send 12345 Will be home soon
# set the geo location
geo fix 48 51
			</pre><p>
                  		
               </p>
               <p>
                  			For more information on the emulator console please see
                  			<a class="ulink" href="//developer.android.com/guide/developing/tools/emulator.html#console" target="_top"> Emulator Console manual</a>
                  		
               </p>
            </div>
         </div>
         <div class="section" title="21.&nbsp;Deploy your application on a real device">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="deployondevice"></a>21.&nbsp;Deploy your application on a real device
                     </h2>
                  </div>
               </div>
            </div>
            <p>
               		Turn on "USB Debugging" on your device in the settings. Select in the
               		settings Applications &gt; Development, then enable USB
               		debugging. You
               		also need to install the driver for your mobile phone. For details
               		please see
               		<a class="ulink" href="//developer.android.com/guide/developing/device.html" target="_top">Developing on a Device
                  		</a>. Please note that the Android version you are developing for must be 
               		the installed version on your phone.
               	
            </p>
            <p> To select your phone, select the "Run Configurations", select
               		"Manual" selection and select your device. 
            </p>
            <p>
               		
            </p>
            <div class="mediaobject"><img src="images/xrun10.gif.pagespeed.ic.O6taynixdQ.png" alt="The Android Run Configuration on the Target Tab, selecting the &#34;Manual&#34; flag." width="613" height="208"></div>
            <p>
               	
            </p>
            <p>
               		
            </p>
            <div class="mediaobject"><img src="images/xrun20.gif.pagespeed.ic.CkaDkIftv0.png" alt="Show the selection of the real device to deploy on it." width="612" height="193"></div>
            <p>
               	
            </p>
         </div>
         <div class="section" title="22.&nbsp;Thank you">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="thankyou"></a>22.&nbsp;Thank you 
                     </h2>
                  </div>
               </div>
            </div>
            <p>
               		
               	
            </p>
            <p></p>
            <p>
               	Please help me to support this article:
               	
            </p>
            <table>
               <tr>
                  			
                  <td>
                     				<a href="//flattr.com/thing/49772/Tutorials-for-Eclipse-Java-Android-and-Webprogramming" target="_blank">
                        					<img src="//api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0">
                        				</a>
                     			
                  </td>
                  
                  			
                  <td>
                     				
                     <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
                        					<input type="hidden" name="cmd" value="_s-xclick">
                        					<input type="hidden" name="hosted_button_id" value="10463995">
                        					<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
                        					<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
                        				
                     </form>
                     			
                  </td>
                  		
               </tr>
            </table>
            <p>
               
               
               
               	
               
               	
            </p>
         </div>
         <div class="section" title="23.&nbsp;Questions and Discussion">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="questions"></a>23.&nbsp;Questions and Discussion
                     </h2>
                  </div>
               </div>
            </div>
            <p>
               		Before posting questions, please see the
               		<a class="ulink" href="/faq.html" target="_top"> vogella FAQ</a>. If you have questions or find an error in this article please
               		use the
               		<a class="ulink" href="//groups.google.com/group/vogella" target="_top"> www.vogella.de Google Group</a>. I have created a short list
               		<a class="ulink" href="/blog/2010/03/09/asking-community-questions/" target="_top"> how to create good questions
                  		</a> which might also help you.
               	
            </p>
         </div>
         <div class="section" title="24.&nbsp;Links and Literature">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a name="resources"></a>24.&nbsp;Links and Literature
                     </h2>
                  </div>
               </div>
            </div> 
            
            
            <div class="section" title="24.1.&nbsp;Source Code">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="sourcecode"></a>24.1.&nbsp;Source Code
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  		<a class="ulink" href="/code.html" target="_top">Source Code of Examples</a>
                  	
               </p>
            </div>
            <div class="section" title="24.2.&nbsp;Android Resources">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="resources_databinding"></a>24.2.&nbsp;Android Resources
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  			<a class="ulink" href="//dpunkt.de/s/android" target="_top">
                     				Android 2 (German Book)
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="/articles/AndroidListView/article.html" target="_top">
                     				Android ListView and ListActivity
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="/articles/AndroidSQLite/article.html" target="_top">
                     				Android SQlite Database
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="/articles/AndroidWidgets/article.html" target="_top">
                     				Android Widgets
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="/articles/AndroidLiveWallpaper/article.html" target="_top">
                     				Android Live Wallpaper
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="/articles/AndroidServices/article.html/article.html" target="_top">
                     				Android Services
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="/articles/AndroidLocationAPI/article.html" target="_top">
                     				Android Location API and Google Maps
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="/articles/AndroidIntent/article.html" target="_top">
                     				Android Intents
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="/articles/AndroidNetworking/article.html" target="_top">
                     				Android and Networking
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="//code.google.com/intl/de-DE/android/" target="_top">
                     				Android Homepage
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="//developer.android.com/" target="_top">
                     				Android Developer Homepage 
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="//code.google.com/p/android/issues/list" target="_top">
                     				Android Issues / Bugs
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="//groups.google.com/group/android-developers" target="_top">
                     				Android Google Groups
                     			</a>
                  		
               </p>
               <p>
                  			<a class="ulink" href="//android-developers.blogspot.com/2009/04/live-folders.html" target="_top">
                     				Android Live Folder
                     			</a>
                  		
               </p>
            </div>
            <div class="section" title="24.3.&nbsp;vogella Resources">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a name="resources_general"></a>24.3.&nbsp;vogella Resources
                        </h3>
                     </div>
                  </div>
               </div>
               <p>
                  		<a class="ulink" href="/training/eclipsercp.html" target="_top"> Eclipse RCP Training </a>(German) Eclipse RCP Training with Lars Vogel
                  	
               </p>
               <p>
                  		<a class="ulink" href="article.html" target="_top"> Android Tutorial
                     		</a> Introduction to Android Programming
                  	
               </p>
               <p>
                  		<a class="ulink" href="/articles/GWT/article.html" target="_top"> GWT Tutorial
                     		</a> Program in Java and compile to JavaScript and HTML
                  	
               </p>
               <p>
                  		<a class="ulink" href="/articles/EclipseRCP/article.html" target="_top"> Eclipse RCP Tutorial
                     		</a> Create native applications in Java
                  	
               </p>
               <p>
                  		<a class="ulink" href="/articles/JUnit/article.html" target="_top"> JUnit Tutorial
                     		</a> Test your application
                  	
               </p>
               <p>
                  		<a class="ulink" href="/articles/Git/article.html" target="_top"> Git Tutorial
                     		</a> Put everything you have under distributed version control system
                  	
               </p>
            </div>
         </div>
      </div>
      
      
      
   </body>
</html>